{ ---------------------------------------------------------------------------- }
{ GALLUS ~ CHOIR                                                               }
{ This script is part of the GALLUS ~ PROJET                                   }
{ Author : HEPARO / Hervé PARONNAUD                                            }
{ Contact / Support : contact@heparo.com                                       }
{ This script is licensed under a Creative Commons CC BY 4.0 License           }
{ https://creativecommons.org/licenses/by/4.0/                                 }
{ ---------------------------------------------------------------------------- }
on init

	set_snapshot_type(1) {init callback not executed upon snapshot loading}	
	make_perfview
	set_script_title("GALLUS ~ CHOIR")
	set_ui_width_px(964)
	set_ui_height_px(242) { wallpaper_height_px - 68 }
	set_control_par_str($INST_ICON_ID,$CONTROL_PAR_PICTURE,"ico")
	message("")
	
	{ CONSTANTS ---------------------------------------------------------------- }
	
	declare const $TRUE := 1
	declare const $FALSE := 0
	
	declare const $ONE := 1
	declare const $ZERO := 0
	
	declare const $PLUS := 1
	declare const $MINUS := -1
	
	declare const $UP := -1
	declare const $STATIC := 0
	declare const $DOWN := 1
	
	declare @EMPTY
	@EMPTY := ""
	
	{ SPECIFIC CONSTANTS ------------------------------------------------------- }
	
	declare const $SLOT_LIMITER := 7	
	
	{ INSTRUMENT INDEXES ------------------------------------------------------- }
	
	{ DYNAMICS GAINER }
	declare const $SLOT_GN_DYN := 0
	
	{ DYNAMICS CUTOFF }
	declare const $SLOT_CO_DYN := 1
	
	{ EXPRESSION GAINER }
	declare const $SLOT_GN_EXP := 2
	
	{ CHARACTER / FUNDAMENTAL EQ1 }
	declare const $SLOT_FUND_EQ := 2
	
	{ REVERB }
	declare const $SLOT_REVERB := 0
	
	{ STEREO }
	declare const $SLOT_STEREO := 5	
	
	{ SEND LEVELS }
	declare const $SLOT_SEND := 7
	
	{ BUSSES }
	declare const $BUS_S_GRP1 := 0
	declare const $BUS_S_GRP2 := 1
	declare const $BUS_A_GRP1 := 2
	declare const $BUS_A_GRP2 := 3
	declare const $BUS_T_GRP1 := 4
	declare const $BUS_T_GRP2 := 5
	declare const $BUS_B_GRP1 := 6
	declare const $BUS_B_GRP2 := 7
	
	{ GROUPS }
	declare const $GROUP_PER_DIVISI := 6
	declare const $GROUP_PER_SECTION := 2 * $GROUP_PER_DIVISI
	
	{ VARIABLES ---------------------------------------------------------------- }
	
	declare $index0
	declare $index1
	declare $index2
	
	declare $intVar0
	declare $intVar1
	declare $intVar2
	
	declare ~realVar0
	declare ~realVar1
	declare ~realVar2
	
	declare @strVar0
	declare @strVar1
	declare @strVar2
	
	declare $initFlag := $TRUE
	
	declare $previousEvent
	declare $PreviousNote
		
	declare $newNote
	declare $newTune
	declare $newVelocity
	declare $newVolume
	declare $newPan
	
	declare $forcedVelocity := 64	

	declare $knobSelLastValue := $ZERO	
	declare $knobSelDirection := $ZERO
		
	declare $flegatoDuration := $ZERO
	
	declare $verifiedModuleIndex := $ZERO
	declare $verifiedModuleMaxIndex := $ZERO
	
	declare $verifiedModuleIndex1 := $ZERO
	declare $verifiedModuleIndex2 := $ZERO
	declare $verifiedModuleIndex3 := $ZERO
	declare $verifiedModuleIndex4 := $ZERO
	declare $verifiedModuleIndex5 := $ZERO
	
	declare $currentKeyswitch := $ZERO	
	
	{ UI VARIABLES ------------------------------------------------------------- }
	
	declare const $FONT_BLACK := 16
	declare const $FONT_WHITE := 17
	declare $fontColor := $FONT_WHITE
	
	declare const $ALIGN_RIGHT := 2
	declare const $ALIGN_MIDDLE := 1
	declare const $ALIGN_LEFT := 0
	declare $fontAlign := $ALIGN_RIGHT
	
	declare $PosY := 80
	declare const $IncrY := 20
	
	declare const $Col1X := 125
	declare const $Col2X := 275
	declare const $Col3X := 600
	declare const $Col4X := 650
	declare const $Col5X := 770
	
	declare %Timer[4] := (0)
	declare const $TIMER_DEFAULT := 0
	declare const $TIMER_VELOCITY := 1
	
	declare const $TEMPO_DEFAULT := 1500000
	declare const $TEMPO_VELOCITY := 3000000	
	
	declare $Silent := $FALSE
	
	declare const ~X_MIN := 260.0
	declare const ~X_MAX := 550.0
	
	declare const $DEFAULT_X_LEFT := 350
	declare const $DEFAULT_X_RIGHT := 450
	
	{ MODULES ------------------------------------------------------------------ }
	
	declare const $MODULE_DYNAMICS := 0
	declare const $MODULE_EXPRESSION := 1
	declare const $MODULE_FKLEGATO := 2
	declare const $MODULE_HUMANIZE := 3
	declare const $MODULE_FORCED_VELOCITY := 4
	declare const $MODULE_STEREO_S := 5	
	declare const $MODULE_STEREO_P := 6
	declare const $MODULE_REVERB_SLEVEL := 7
	declare const $MODULE_REVERB_MODE := 8
	declare const $MODULE_VELO_SAMPlE_START := 9
	declare const $MODULE_VELO_VOLUME := 10
	declare const $MODULE_VELO_ATTACK := 11
	declare const $MODULE_VELO_RELEASE := 12	
	declare const $MODULE_ATTACK := 13
	
	declare const $MODULE_FUNDAMENTAL_GAIN := 14	
	declare const $MODULE_FUNDAMENTAL_WIDTH := 15
	
	declare const $MODULE_S_GRP1_VOLUME := 16
	declare const $MODULE_S_GRP1_PAN := 17
	declare const $MODULE_S_GRP2_VOLUME := 18
	declare const $MODULE_S_GRP2_PAN := 19
	declare const $MODULE_A_GRP1_VOLUME := 20
	declare const $MODULE_A_GRP1_PAN := 21
	declare const $MODULE_A_GRP2_VOLUME := 22
	declare const $MODULE_A_GRP2_PAN := 23
	declare const $MODULE_T_GRP1_VOLUME := 24
	declare const $MODULE_T_GRP1_PAN := 25
	declare const $MODULE_T_GRP2_VOLUME := 26
	declare const $MODULE_T_GRP2_PAN := 27
	declare const $MODULE_B_GRP1_VOLUME := 28
	declare const $MODULE_B_GRP1_PAN := 29
	declare const $MODULE_B_GRP2_VOLUME := 30
	declare const $MODULE_B_GRP2_PAN := 31
		
	declare const $MODULES_COUNT := 32
	declare const $MODULES_VISIBLE := 5
	
	declare const $KNOBSEL_MAX_INDEX := $MODULES_COUNT - $MODULES_VISIBLE
	
	declare $moduleIndex := $ZERO	
	declare $moduleEditedIndex := $ZERO
	declare $moduleEditedValue := $ZERO
	
	declare !modulesLabels[$MODULES_COUNT]	
	$index0 := $ZERO
	while($index0 < $MODULES_COUNT)
		!modulesLabels[$index0] := @EMPTY
		inc ($index0)
	end while	
	!modulesLabels[$MODULE_DYNAMICS] := "DYNAMICS | CC1 | Default = 64"
	!modulesLabels[$MODULE_EXPRESSION] := "EXPRESSION | CC11 | Default = 64"
	!modulesLabels[$MODULE_FORCED_VELOCITY]  := "VELOCITY | FORCED | Default = 64 (mf)"
	!modulesLabels[$MODULE_FKLEGATO] := "FAKE LEGATO | Default transition = 250ms"
	!modulesLabels[$MODULE_HUMANIZE] := "HUMANIZE | Default amount = 10%"
	!modulesLabels[$MODULE_STEREO_S] := "STEREO | Spread | Default = 0%"
	!modulesLabels[$MODULE_STEREO_P] := "STEREO | Pan | Default = Center"
	!modulesLabels[$MODULE_REVERB_SLEVEL] := "REVERB | Send Level | Default = -18dB"
	!modulesLabels[$MODULE_REVERB_MODE] := "REVERB | Mode | Default = Hall"
	!modulesLabels[$MODULE_VELO_SAMPlE_START] := "MODULATION | Velocity for Sample Start | Default = 20%"
	!modulesLabels[$MODULE_VELO_VOLUME] := "MODULATION | Velocity for Volume | Default = 20%"
	!modulesLabels[$MODULE_VELO_ATTACK] := "MODULATION | Velocity for Attack | Default = 20%"
	!modulesLabels[$MODULE_VELO_RELEASE] := "MODULATION | Velocity for Release | Default = 20%"
	!modulesLabels[$MODULE_ATTACK] := "ATTACK | Default = xxx"	
	!modulesLabels[$MODULE_S_GRP1_VOLUME] := "SOPRANO G1 | Bus Volume | Default = 0dB"
	!modulesLabels[$MODULE_S_GRP1_PAN] := "SOPRANO G1 | Bus Pan | Default = 35L"	
	!modulesLabels[$MODULE_S_GRP2_VOLUME] := "SOPRANO G2 | Bus Volume | Default = 0dB"
	!modulesLabels[$MODULE_S_GRP2_PAN] := "SOPRANO G2 | Bus Pan | Default = 35R"
	!modulesLabels[$MODULE_A_GRP1_VOLUME] := "ALTO G1 | Bus Volume | Default = 0dB"
	!modulesLabels[$MODULE_A_GRP1_PAN] := "ALTO G1 | Bus Pan | Default = 40L"	
	!modulesLabels[$MODULE_A_GRP2_VOLUME] := "ALTO G2 | Bus Volume | Default = 0dB"
	!modulesLabels[$MODULE_A_GRP2_PAN] := "ALTO G2 | Bus Pan | Default = 40R"
	!modulesLabels[$MODULE_T_GRP1_VOLUME] := "TENOR G1 | Bus Volume | Default = 0dB"
	!modulesLabels[$MODULE_T_GRP1_PAN] := "TENOR G1 | Bus Pan | Default = 45L"	
	!modulesLabels[$MODULE_T_GRP2_VOLUME] := "TENOR G2 | Bus Volume | Default = 0dB"
	!modulesLabels[$MODULE_T_GRP2_PAN] := "TENOR G2 | Bus Pan | Default = 45R"
	!modulesLabels[$MODULE_B_GRP1_VOLUME] := "BASS G1 | Bus Volume | Default = 0dB"
	!modulesLabels[$MODULE_B_GRP1_PAN] := "BASS G1 | Bus Pan | Default = 50L"	
	!modulesLabels[$MODULE_B_GRP2_VOLUME] := "BASS G2 | Bus Volume | Default = 0dB"
	!modulesLabels[$MODULE_B_GRP2_PAN] := "BASS G2 | Bus Pan | Default = 50R"
	!modulesLabels[$MODULE_FUNDAMENTAL_GAIN] := "FUNDAMENTAL | Gain | Default amount = -3 dB"
	!modulesLabels[$MODULE_FUNDAMENTAL_WIDTH] := "FUNDAMENTAL | Width | Default amount = 0.5 oc"	
		
	declare %modulesDefaultStatus[$MODULES_COUNT] := ($FALSE)	
		
	declare %modulesDefaultValues[$MODULES_COUNT] := ($ZERO)
	%modulesDefaultValues[$MODULE_FORCED_VELOCITY] := 510000
	%modulesDefaultValues[$MODULE_DYNAMICS] := 510000
	%modulesDefaultValues[$MODULE_EXPRESSION] := 510000
	%modulesDefaultValues[$MODULE_FKLEGATO] := 500000
	%modulesDefaultValues[$MODULE_HUMANIZE] := 100000
	%modulesDefaultValues[$MODULE_STEREO_S] := 500000
	%modulesDefaultValues[$MODULE_STEREO_P] := 500000
	%modulesDefaultValues[$MODULE_REVERB_SLEVEL] := 315551 {397115 = -12dB}
	%modulesDefaultValues[$MODULE_REVERB_MODE] := 0
	%modulesDefaultValues[$MODULE_VELO_SAMPlE_START] := 447000 { 20% }
	%modulesDefaultValues[$MODULE_VELO_VOLUME] := 447000 { 20% }
	%modulesDefaultValues[$MODULE_VELO_ATTACK] := 447000 { 20% }
	%modulesDefaultValues[$MODULE_VELO_RELEASE] := 447000 { 20% }
	%modulesDefaultValues[$MODULE_ATTACK] := 0 { 0 ms }
	%modulesDefaultValues[$MODULE_S_GRP1_VOLUME] := 630000
	%modulesDefaultValues[$MODULE_S_GRP1_PAN] := 325000	
	%modulesDefaultValues[$MODULE_S_GRP2_VOLUME] := 630000
	%modulesDefaultValues[$MODULE_S_GRP2_PAN] := 675000
	%modulesDefaultValues[$MODULE_A_GRP1_VOLUME] := 630000
	%modulesDefaultValues[$MODULE_A_GRP1_PAN] := 300000	
	%modulesDefaultValues[$MODULE_A_GRP2_VOLUME] := 630000
	%modulesDefaultValues[$MODULE_A_GRP2_PAN] := 700000
	%modulesDefaultValues[$MODULE_T_GRP1_VOLUME] := 630000
	%modulesDefaultValues[$MODULE_T_GRP1_PAN] := 275000	
	%modulesDefaultValues[$MODULE_T_GRP2_VOLUME] := 630000
	%modulesDefaultValues[$MODULE_T_GRP2_PAN] := 725000
	%modulesDefaultValues[$MODULE_B_GRP1_VOLUME] := 630000
	%modulesDefaultValues[$MODULE_B_GRP1_PAN] := 250000	
	%modulesDefaultValues[$MODULE_B_GRP2_VOLUME] := 630000
	%modulesDefaultValues[$MODULE_B_GRP2_PAN] := 750000
	%modulesDefaultValues[$MODULE_FUNDAMENTAL_GAIN] := 417000 { -3db }
	%modulesDefaultValues[$MODULE_FUNDAMENTAL_WIDTH] := 62500 { 0.5oc }
	
	declare %modulesStatus[$MODULES_COUNT] := ($FALSE)		
	
	declare %modulesValues[$MODULES_COUNT] := ($ZERO)
	
	$index0 := $ZERO
	while( $index0 < $MODULES_COUNT )
		%modulesStatus[$index0] := %modulesDefaultStatus[$index0]
		%modulesValues[$index0] := %modulesDefaultValues[$index0]
		inc($index0)
	end while
	
	declare %modulesAllowed[$MODULES_COUNT] := ($TRUE)
	
	declare %keyswitches_note[128] := ($MINUS)	
	declare $isKeyswitchUi
	
	{ BACKGROUND ------------------------------------------------------------- }
	
	declare ui_label $bgLbl(1,1)
	set_text ($bgLbl,"")
	declare $bgLbl_id := get_ui_id($bgLbl)
	set_control_par_str($bgLbl_id,$CONTROL_PAR_PICTURE,"Bg_Default")
	set_control_par($bgLbl_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($bgLbl_id,$CONTROL_PAR_WIDTH,635)
	set_control_par($bgLbl_id,$CONTROL_PAR_HEIGHT,64)
	set_control_par($bgLbl_id,$CONTROL_PAR_POS_X,0)
	set_control_par($bgLbl_id,$CONTROL_PAR_POS_Y,263)
	
	{ VELOCITY ----------------------------------------------------------------- }
	
	declare ui_slider $KnobVelocity(0,127)
	declare $KnobVelocity_id := get_ui_id($KnobVelocity)	
	set_control_par_str($KnobVelocity_id,$CONTROL_PAR_PICTURE,"Velocity")
	set_control_par($KnobVelocity_id,$CONTROL_PAR_POS_X,10)
	set_control_par($KnobVelocity_id,$CONTROL_PAR_POS_Y,28)
	set_control_par($KnobVelocity_id,$CONTROL_PAR_MOUSE_BEHAVIOUR,-1000)
	set_control_par($KnobVelocity_id,$CONTROL_PAR_DEFAULT_VALUE,$ZERO)
	set_control_par($KnobVelocity_id,$CONTROL_PAR_VALUE,$ZERO)
	
	{ SELECTOR ----------------------------------------------------------------- }
	
	declare ui_slider $KnobSel(0,$KNOBSEL_MAX_INDEX)
	declare $KnobSel_id := get_ui_id($KnobSel)	
	set_control_par_str($KnobSel_id,$CONTROL_PAR_PICTURE,"Knob")
	set_control_par($KnobSel_id,$CONTROL_PAR_POS_X,134)
	set_control_par($KnobSel_id,$CONTROL_PAR_POS_Y,84)	
	set_control_par($KnobSel_id,$CONTROL_PAR_MOUSE_BEHAVIOUR,-1000)
	set_control_par($KnobSel_id,$CONTROL_PAR_DEFAULT_VALUE,$ZERO)
	set_control_par($KnobSel_id,$CONTROL_PAR_VALUE,$ZERO)	
		
	{ EDITED VALUE ------------------------------------------------------------- }
	
	declare ui_label $editedValLbl(1,1)
	set_text ($editedValLbl,@EMPTY)
	hide_part($editedValLbl,$HIDE_PART_BG)
	declare $editedValLbl_id := get_ui_id($editedValLbl)
	set_control_par($editedValLbl_id,$CONTROL_PAR_WIDTH,110)
	set_control_par($editedValLbl_id,$CONTROL_PAR_POS_X,725)
	set_control_par($editedValLbl_id,$CONTROL_PAR_POS_Y,180)
	set_control_par($editedValLbl_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($editedValLbl_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_LEFT)
	
	{ ITEM 1 ------------------------------------------------------------------- }	
	
	while( $verifiedModuleIndex < $MODULES_COUNT and %modulesAllowed[$verifiedModuleIndex] = $FALSE )
		inc($verifiedModuleIndex)
	end while
	
	declare ui_label $item1Lbl(1,1)	
	set_text($item1Lbl,!modulesLabels[$verifiedModuleIndex])
	hide_part($item1Lbl,$HIDE_PART_BG)
	declare $item1Lbl_id := get_ui_id($item1Lbl)	
	set_control_par($item1Lbl_id,$CONTROL_PAR_WIDTH,300)
	set_control_par($item1Lbl_id,$CONTROL_PAR_POS_X,$Col2X)
	set_control_par($item1Lbl_id,$CONTROL_PAR_POS_Y,$PosY+1)
	set_control_par($item1Lbl_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($item1Lbl_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_LEFT)
	
	declare ui_switch $item1Toggle	
	declare $item1Toggle_id := get_ui_id($item1Toggle)		
	set_control_par_str($item1Toggle_id,$CONTROL_PAR_PICTURE,"Switch")
	set_control_par($item1Toggle_id,$CONTROL_PAR_WIDTH,36)
	set_control_par($item1Toggle_id,$CONTROL_PAR_HEIGHT,18)
	set_control_par($item1Toggle_id,$CONTROL_PAR_POS_X,$Col3X)
	set_control_par($item1Toggle_id,$CONTROL_PAR_POS_Y,$PosY-2)
	set_control_par($item1Toggle_id,$CONTROL_PAR_TEXTPOS_Y,1000)
	set_control_par($item1Toggle_id,$CONTROL_PAR_VALUE,%modulesStatus[$verifiedModuleIndex])
	
	declare ui_slider $item1Slider(0,1000000)	
	declare $item1Slider_id := get_ui_id($item1Slider)
	set_control_par_str($item1Slider_id,$CONTROL_PAR_PICTURE,"Slider")
	set_control_par($item1Slider_id,$CONTROL_PAR_WIDTH,112)
	set_control_par($item1Slider_id,$CONTROL_PAR_HEIGHT,32)
	set_control_par($item1Slider_id,$CONTROL_PAR_POS_X,$Col4X)
	set_control_par($item1Slider_id,$CONTROL_PAR_POS_Y,$PosY-8)
	set_control_par($item1Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])
	set_control_par($item1Slider_id,$CONTROL_PAR_VALUE,%modulesValues[$verifiedModuleIndex])
		
	$PosY := $PosY + $IncrY
	
	{ ITEM 2 ------------------------------------------------------------------- }
	
	inc($verifiedModuleIndex)
	while( $verifiedModuleIndex < $MODULES_COUNT and %modulesAllowed[$verifiedModuleIndex] = $FALSE )
		inc($verifiedModuleIndex)
	end while
	
	declare ui_label $item2Lbl(1,1)	
	set_text($item2Lbl,!modulesLabels[$verifiedModuleIndex])
	hide_part($item2Lbl,$HIDE_PART_BG)
	declare $item2Lbl_id := get_ui_id($item2Lbl)	
	set_control_par($item2Lbl_id,$CONTROL_PAR_WIDTH,300)
	set_control_par($item2Lbl_id,$CONTROL_PAR_POS_X,$Col2X)
	set_control_par($item2Lbl_id,$CONTROL_PAR_POS_Y,$PosY+1)
	set_control_par($item2Lbl_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($item2Lbl_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_LEFT)
	
	declare ui_switch $item2Toggle
	declare $item2Toggle_id := get_ui_id($item2Toggle)		
	set_control_par_str($item2Toggle_id,$CONTROL_PAR_PICTURE,"Switch")
	set_control_par($item2Toggle_id,$CONTROL_PAR_WIDTH,36)
	set_control_par($item2Toggle_id,$CONTROL_PAR_HEIGHT,18)
	set_control_par($item2Toggle_id,$CONTROL_PAR_POS_X,$Col3X)
	set_control_par($item2Toggle_id,$CONTROL_PAR_POS_Y,$PosY-1)
	set_control_par($item2Toggle_id,$CONTROL_PAR_TEXTPOS_Y,1000)
	set_control_par($item2Toggle_id,$CONTROL_PAR_VALUE,%modulesStatus[$verifiedModuleIndex])
	
	declare ui_slider $item2Slider(0,1000000)
	declare $item2Slider_id := get_ui_id($item2Slider)
	set_control_par_str($item2Slider_id,$CONTROL_PAR_PICTURE,"Slider")
	set_control_par($item2Slider_id,$CONTROL_PAR_WIDTH,112)
	set_control_par($item2Slider_id,$CONTROL_PAR_HEIGHT,32)
	set_control_par($item2Slider_id,$CONTROL_PAR_POS_X,$Col4X)
	set_control_par($item2Slider_id,$CONTROL_PAR_POS_Y,$PosY-7)
	set_control_par($item2Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])
	set_control_par($item2Slider_id,$CONTROL_PAR_VALUE,%modulesValues[$verifiedModuleIndex])
		
	$PosY := $PosY + $IncrY
	
	{ ITEM 3 ------------------------------------------------------------------- }
	
	inc($verifiedModuleIndex)
	while( $verifiedModuleIndex < $MODULES_COUNT and %modulesAllowed[$verifiedModuleIndex] = $FALSE )
		inc($verifiedModuleIndex)
	end while
	
	declare ui_label $item3Lbl(1,1)	
	set_text($item3Lbl,!modulesLabels[$verifiedModuleIndex])
	hide_part($item3Lbl,$HIDE_PART_BG)
	declare $item3Lbl_id := get_ui_id($item3Lbl)	
	set_control_par($item3Lbl_id,$CONTROL_PAR_WIDTH,300)
	set_control_par($item3Lbl_id,$CONTROL_PAR_POS_X,$Col2X)
	set_control_par($item3Lbl_id,$CONTROL_PAR_POS_Y,$PosY+1)
	set_control_par($item3Lbl_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($item3Lbl_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_LEFT)
	
	declare ui_switch $item3Toggle
	declare $item3Toggle_id := get_ui_id($item3Toggle)		
	set_control_par_str($item3Toggle_id,$CONTROL_PAR_PICTURE,"Switch")
	set_control_par($item3Toggle_id,$CONTROL_PAR_WIDTH,36)
	set_control_par($item3Toggle_id,$CONTROL_PAR_HEIGHT,18)
	set_control_par($item3Toggle_id,$CONTROL_PAR_POS_X,$Col3X)
	set_control_par($item3Toggle_id,$CONTROL_PAR_POS_Y,$PosY-1)
	set_control_par($item3Toggle_id,$CONTROL_PAR_TEXTPOS_Y,1000)
	set_control_par($item3Toggle_id,$CONTROL_PAR_VALUE,%modulesStatus[$verifiedModuleIndex])
	
	declare ui_slider $item3Slider(0,1000000)
	declare $item3Slider_id := get_ui_id($item3Slider)
	set_control_par_str($item3Slider_id,$CONTROL_PAR_PICTURE,"Slider")
	set_control_par($item3Slider_id,$CONTROL_PAR_WIDTH,112)
	set_control_par($item3Slider_id,$CONTROL_PAR_HEIGHT,32)
	set_control_par($item3Slider_id,$CONTROL_PAR_POS_X,$Col4X)
	set_control_par($item3Slider_id,$CONTROL_PAR_POS_Y,$PosY-7)
	set_control_par($item3Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])
	set_control_par($item3Slider_id,$CONTROL_PAR_VALUE,%modulesValues[$verifiedModuleIndex])
		
	$PosY := $PosY + $IncrY
	
	{ ITEM 4 ------------------------------------------------------------------- }
	
	inc($verifiedModuleIndex)
	while( $verifiedModuleIndex < $MODULES_COUNT and %modulesAllowed[$verifiedModuleIndex] = $FALSE )
		inc($verifiedModuleIndex)
	end while
	
	declare ui_label $item4Lbl(1,1)	
	set_text($item4Lbl,!modulesLabels[$verifiedModuleIndex])
	hide_part($item4Lbl,$HIDE_PART_BG)
	declare $item4Lbl_id := get_ui_id($item4Lbl)	
	set_control_par($item4Lbl_id,$CONTROL_PAR_WIDTH,300)
	set_control_par($item4Lbl_id,$CONTROL_PAR_POS_X,$Col2X)
	set_control_par($item4Lbl_id,$CONTROL_PAR_POS_Y,$PosY+1)
	set_control_par($item4Lbl_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($item4Lbl_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_LEFT)
	
	declare ui_switch $item4Toggle
	declare $item4Toggle_id := get_ui_id($item4Toggle)		
	set_control_par_str($item4Toggle_id,$CONTROL_PAR_PICTURE,"Switch")
	set_control_par($item4Toggle_id,$CONTROL_PAR_WIDTH,36)
	set_control_par($item4Toggle_id,$CONTROL_PAR_HEIGHT,18)
	set_control_par($item4Toggle_id,$CONTROL_PAR_POS_X,$Col3X)
	set_control_par($item4Toggle_id,$CONTROL_PAR_POS_Y,$PosY-1)
	set_control_par($item4Toggle_id,$CONTROL_PAR_TEXTPOS_Y,1000)
	set_control_par($item4Toggle_id,$CONTROL_PAR_VALUE,%modulesStatus[$verifiedModuleIndex])
	
	declare ui_slider $item4Slider(0,1000000)
	declare $item4Slider_id := get_ui_id($item4Slider)
	set_control_par_str($item4Slider_id,$CONTROL_PAR_PICTURE,"Slider")
	set_control_par($item4Slider_id,$CONTROL_PAR_WIDTH,112)
	set_control_par($item4Slider_id,$CONTROL_PAR_HEIGHT,32)
	set_control_par($item4Slider_id,$CONTROL_PAR_POS_X,$Col4X)
	set_control_par($item4Slider_id,$CONTROL_PAR_POS_Y,$PosY-7)
	set_control_par($item4Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])
	set_control_par($item4Slider_id,$CONTROL_PAR_VALUE,%modulesValues[$verifiedModuleIndex])
		
	$PosY := $PosY + $IncrY
	
	{ ITEM 5 ------------------------------------------------------------------- }
	
	
	inc($verifiedModuleIndex)
	while( $verifiedModuleIndex < $MODULES_COUNT and %modulesAllowed[$verifiedModuleIndex] = $FALSE )
		inc($verifiedModuleIndex)
	end while
	
	declare ui_label $item5Lbl(1,1)	
	set_text($item5Lbl,!modulesLabels[$verifiedModuleIndex])
	hide_part($item5Lbl,$HIDE_PART_BG)
	declare $item5Lbl_id := get_ui_id($item5Lbl)	
	set_control_par($item5Lbl_id,$CONTROL_PAR_WIDTH,300)
	set_control_par($item5Lbl_id,$CONTROL_PAR_POS_X,$Col2X)
	set_control_par($item5Lbl_id,$CONTROL_PAR_POS_Y,$PosY+1)
	set_control_par($item5Lbl_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($item5Lbl_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_LEFT)
	
	declare ui_switch $item5Toggle
	declare $item5Toggle_id := get_ui_id($item5Toggle)		
	set_control_par_str($item5Toggle_id,$CONTROL_PAR_PICTURE,"Switch")
	set_control_par($item5Toggle_id,$CONTROL_PAR_WIDTH,36)
	set_control_par($item5Toggle_id,$CONTROL_PAR_HEIGHT,18)
	set_control_par($item5Toggle_id,$CONTROL_PAR_POS_X,$Col3X)
	set_control_par($item5Toggle_id,$CONTROL_PAR_POS_Y,$PosY-1)
	set_control_par($item5Toggle_id,$CONTROL_PAR_TEXTPOS_Y,1000)
	set_control_par($item5Toggle_id,$CONTROL_PAR_VALUE,%modulesStatus[$verifiedModuleIndex])
	
	declare ui_slider $item5Slider(0,1000000)
	declare $item5Slider_id := get_ui_id($item5Slider)
	set_control_par_str($item5Slider_id,$CONTROL_PAR_PICTURE,"Slider")
	set_control_par($item5Slider_id,$CONTROL_PAR_WIDTH,112)
	set_control_par($item5Slider_id,$CONTROL_PAR_HEIGHT,32)
	set_control_par($item5Slider_id,$CONTROL_PAR_POS_X,$Col4X)
	set_control_par($item5Slider_id,$CONTROL_PAR_POS_Y,$PosY-7)
	set_control_par($item5Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])
	set_control_par($item5Slider_id,$CONTROL_PAR_VALUE,%modulesValues[$verifiedModuleIndex])
		
	$PosY := $PosY + $IncrY

	{ CONFIGURATION ------------------------------------------------------------ }
	
	declare ui_label $configBg(1,1)
	set_text ($configBg,"")
	declare $configBg_id := get_ui_id($configBg)
	set_control_par($configBg_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($configBg_id,$CONTROL_PAR_WIDTH,964)
	set_control_par($configBg_id,$CONTROL_PAR_HEIGHT,75)
	set_control_par($configBg_id,$CONTROL_PAR_POS_X,0)
	set_control_par($configBg_id,$CONTROL_PAR_POS_Y,0)	
	set_control_par($configBg_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	declare ui_button $configButton
	set_text ($configButton,@EMPTY)
	declare $configButton_id := get_ui_id($configButton)	
	set_control_par_str($configButton_id,$CONTROL_PAR_PICTURE,"Config")
	set_control_par($configButton_id, $CONTROL_PAR_POS_X, 880)
	set_control_par($configButton_id, $CONTROL_PAR_POS_Y, 3)
	
	declare ui_panel $configPanel
	declare $configPanel_id := get_ui_id($configPanel)	
	move_control($configPanel,0,0)
	set_control_par($configPanel_id,$CONTROL_PAR_Z_LAYER,1)
	
	declare ui_label $configLabel (6,1)
	set_text ($configLabel,"CONFIGURATION")
	declare $configLabel_id := get_ui_id($configLabel)	
	set_control_par($configLabel_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($configLabel_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($configLabel_id,$CONTROL_PAR_WIDTH,115)
	set_control_par($configLabel_id, $CONTROL_PAR_POS_X, 1)
	set_control_par($configLabel_id, $CONTROL_PAR_POS_Y, 3)
	
	declare ui_button $configDoneButton
	set_text ($configDoneButton,"Done")	
	declare $configDoneButton_id := get_ui_id($configDoneButton)	
	set_control_par($configDoneButton_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($configDoneButton_id,$CONTROL_PAR_WIDTH,100)
	set_control_par($configDoneButton_id, $CONTROL_PAR_POS_X, 800)
	set_control_par($configDoneButton_id, $CONTROL_PAR_POS_Y, 55)
	
	declare ui_button $defaultValuesButton
	set_text ($defaultValuesButton,"Default Values")	
	declare $defaultValuesButton_id := get_ui_id($defaultValuesButton)	
	set_control_par($defaultValuesButton_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($defaultValuesButton_id,$CONTROL_PAR_WIDTH,100)
	set_control_par($defaultValuesButton_id, $CONTROL_PAR_POS_X, 800)
	set_control_par($defaultValuesButton_id, $CONTROL_PAR_POS_Y, 37)
	
	declare ui_label $titleEditLabel (1,1)
	set_text ($titleEditLabel,"Title")
	declare $titleEditLabel_id := get_ui_id($titleEditLabel)	
	set_control_par($titleEditLabel_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($titleEditLabel_id,$CONTROL_PAR_WIDTH,100)
	set_control_par($titleEditLabel_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($titleEditLabel_id, $CONTROL_PAR_POS_X, 122)
	set_control_par($titleEditLabel_id, $CONTROL_PAR_POS_Y, 3)
	
	declare ui_text_edit @titleEdit
	declare $titleEdit_id := get_ui_id(@titleEdit)	
	set_control_par($titleEdit_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par_str($titleEdit_id,$CONTROL_PAR_TEXT,"empty")
	set_control_par($titleEdit_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($titleEdit_id,$CONTROL_PAR_WIDTH,170)
	set_control_par($titleEdit_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_LEFT)
	set_control_par_str($titleEdit_id,$CONTROL_PAR_PICTURE,"Bg_Default")	
	set_control_par($titleEdit_id, $CONTROL_PAR_POS_X, 225)
	set_control_par($titleEdit_id, $CONTROL_PAR_POS_Y, 3)
	
	declare ui_label $subtitleEditLabel (1,1)
	set_text ($subtitleEditLabel,"Subtitle")
	declare $subtitleEditLabel_id := get_ui_id($subtitleEditLabel)	
	set_control_par($subtitleEditLabel_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($subtitleEditLabel_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($subtitleEditLabel_id,$CONTROL_PAR_WIDTH,100)
	set_control_par($subtitleEditLabel_id, $CONTROL_PAR_POS_X, 122)
	set_control_par($subtitleEditLabel_id, $CONTROL_PAR_POS_Y, 23)
	
	declare ui_text_edit @subtitleEdit	
	declare $subtitleEdit_id := get_ui_id(@subtitleEdit)	
	set_control_par($subtitleEdit_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par_str($subtitleEdit_id,$CONTROL_PAR_TEXT,"empty")
	set_control_par($subtitleEdit_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($subtitleEdit_id,$CONTROL_PAR_WIDTH,170)
	set_control_par($subtitleEdit_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_LEFT)
	set_control_par_str($subtitleEdit_id,$CONTROL_PAR_PICTURE,"Bg_Default")	
	set_control_par($subtitleEdit_id, $CONTROL_PAR_POS_X, 225)
	set_control_par($subtitleEdit_id, $CONTROL_PAR_POS_Y, 23)

	declare ui_switch $disableSopranoSwitch
	set_text ($disableSopranoSwitch,"Disable Soprano")	
	move_control($disableSopranoSwitch,4,2)
	declare $disableSopranoSwitch_id := get_ui_id($disableSopranoSwitch)	
	set_control_par($disableSopranoSwitch_id,$CONTROL_PAR_DEFAULT_VALUE,$TRUE)
	set_control_par($disableSopranoSwitch_id,$CONTROL_PAR_VALUE,$TRUE)
	set_control_par($disableSopranoSwitch_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($disableSopranoSwitch_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($disableSopranoSwitch_id, $CONTROL_PAR_POS_X, 550)
	set_control_par($disableSopranoSwitch_id, $CONTROL_PAR_POS_Y, 3)
	
	declare ui_switch $disableAltoSwitch
	set_text ($disableAltoSwitch,"Disable Alto")	
	move_control($disableAltoSwitch,4,3)
	declare $disableAltoSwitch_id := get_ui_id($disableAltoSwitch)	
	set_control_par($disableAltoSwitch_id,$CONTROL_PAR_DEFAULT_VALUE,$TRUE)
	set_control_par($disableAltoSwitch_id,$CONTROL_PAR_VALUE,$TRUE)
	set_control_par($disableAltoSwitch_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($disableAltoSwitch_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($disableAltoSwitch_id, $CONTROL_PAR_POS_X, 550)
	set_control_par($disableAltoSwitch_id, $CONTROL_PAR_POS_Y, 23)
	
	
	declare ui_switch $disableTenorSwitch
	set_text ($disableTenorSwitch,"Disable Tenor")	
	move_control($disableTenorSwitch,4,4)
	declare $disableTenorSwitch_id := get_ui_id($disableTenorSwitch)	
	set_control_par($disableTenorSwitch_id,$CONTROL_PAR_DEFAULT_VALUE,$TRUE)
	set_control_par($disableTenorSwitch_id,$CONTROL_PAR_VALUE,$TRUE)
	set_control_par($disableTenorSwitch_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($disableTenorSwitch_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($disableTenorSwitch_id, $CONTROL_PAR_POS_X, 635)
	set_control_par($disableTenorSwitch_id, $CONTROL_PAR_POS_Y, 3)
	
	declare ui_switch $disableBassSwitch
	set_text ($disableBassSwitch,"Disable Bass")	
	move_control($disableBassSwitch,4,5)
	declare $disableBassSwitch_id := get_ui_id($disableBassSwitch)	
	set_control_par($disableBassSwitch_id,$CONTROL_PAR_DEFAULT_VALUE,$TRUE)
	set_control_par($disableBassSwitch_id,$CONTROL_PAR_VALUE,$TRUE)
	set_control_par($disableBassSwitch_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($disableBassSwitch_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($disableBassSwitch_id, $CONTROL_PAR_POS_X, 635)
	set_control_par($disableBassSwitch_id, $CONTROL_PAR_POS_Y, 23)
	
	
	declare ui_switch $dynamicsDrivenByVel
	set_text ($dynamicsDrivenByVel,"No CC1 = VELO")	
	set_control_help($dynamicsDrivenByVel,"If [ON] then if DYNAMICS CC1 is disabled then DYNAMICS is computed with Velocity. If [OFF] then Dynamics CC1 is not computed at all")
	move_control($dynamicsDrivenByVel,4,2)
	declare $dynamicsDrivenByVel_id := get_ui_id($dynamicsDrivenByVel)	
	set_control_par($dynamicsDrivenByVel_id,$CONTROL_PAR_DEFAULT_VALUE,$TRUE)
	set_control_par($dynamicsDrivenByVel_id,$CONTROL_PAR_VALUE,$TRUE)
	set_control_par($dynamicsDrivenByVel_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($dynamicsDrivenByVel_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($dynamicsDrivenByVel_id,$CONTROL_PAR_WIDTH,100)
	set_control_par($dynamicsDrivenByVel_id, $CONTROL_PAR_POS_X, 425)
	set_control_par($dynamicsDrivenByVel_id, $CONTROL_PAR_POS_Y, 3)
	
	
	declare ui_switch $expressionDrivenByVel
	set_text ($expressionDrivenByVel,"No CC11 = VELO")
	set_control_help($dynamicsDrivenByVel,"If [ON] then if EXPRESSION CC11 is disabled then EXPRESSION is computed with Velocity. If [OFF] then EXPRESSION CC11 is not computed at all")
	move_control($expressionDrivenByVel,4,3)
	declare $expressionDrivenByVel_id := get_ui_id($expressionDrivenByVel)	
	set_control_par($expressionDrivenByVel_id,$CONTROL_PAR_DEFAULT_VALUE,$TRUE)
	set_control_par($expressionDrivenByVel_id,$CONTROL_PAR_VALUE,$TRUE)
	set_control_par($expressionDrivenByVel_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($expressionDrivenByVel_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($expressionDrivenByVel_id,$CONTROL_PAR_WIDTH,100)
	set_control_par($expressionDrivenByVel_id, $CONTROL_PAR_POS_X, 425)
	set_control_par($expressionDrivenByVel_id, $CONTROL_PAR_POS_Y, 23)
	
	declare ui_switch $attackMode
	set_text ($attackMode,"ATTACK [ LONG ]")
	set_control_help($attackMode,"Set default values for ATTACK LONG or SHORT")
	declare $attackMode_id := get_ui_id($attackMode)	
	set_control_par($attackMode_id,$CONTROL_PAR_DEFAULT_VALUE,$TRUE)
	set_control_par($attackMode_id,$CONTROL_PAR_VALUE,$TRUE)
	set_control_par($attackMode_id,$CONTROL_PAR_PARENT_PANEL,$configPanel_id)
	set_control_par($attackMode_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_RIGHT)
	set_control_par($attackMode_id,$CONTROL_PAR_WIDTH,100)
	set_control_par($attackMode_id, $CONTROL_PAR_POS_X, 425)
	set_control_par($attackMode_id, $CONTROL_PAR_POS_Y, 43)
		
	{ KEYSWITCHES -------------------------------------------------------------- }
	
	$PosY := $PosY + $IncrY	
	
	declare ui_button $ks1Button
	set_text ($ks1Button,@EMPTY)
	declare $ks1Button_id := get_ui_id($ks1Button)	
	set_control_par($ks1Button_id,$CONTROL_PAR_WIDTH,42)
	set_control_par($ks1Button_id,$CONTROL_PAR_HEIGHT,42)
	set_control_par($ks1Button_id, $CONTROL_PAR_POS_X, $Col1X + 0 * (42 + 8) )
	set_control_par($ks1Button_id, $CONTROL_PAR_POS_Y, $PosY)
	set_control_par_str($ks1Button_id,$CONTROL_PAR_PICTURE,"Button_Aa")
	set_key_name(12,"[ARTICULATION] [a]")
	
	declare ui_button $ks2Button
	set_text ($ks2Button,@EMPTY)
	declare $ks2Button_id := get_ui_id($ks2Button)	
	set_control_par($ks2Button_id,$CONTROL_PAR_WIDTH,42)
	set_control_par($ks2Button_id,$CONTROL_PAR_HEIGHT,42)
	set_control_par($ks2Button_id, $CONTROL_PAR_POS_X, $Col1X + 1 * (42 + 8) )
	set_control_par($ks2Button_id, $CONTROL_PAR_POS_Y, $PosY)
	set_control_par_str($ks2Button_id,$CONTROL_PAR_PICTURE,"Button_Ee")
	set_key_name(13,"[ARTICULATION] [e]")
	
	declare ui_button $ks3Button
	set_text ($ks3Button,@EMPTY)
	declare $ks3Button_id := get_ui_id($ks3Button)	
	set_control_par($ks3Button_id,$CONTROL_PAR_WIDTH,42)
	set_control_par($ks3Button_id,$CONTROL_PAR_HEIGHT,42)
	set_control_par($ks3Button_id, $CONTROL_PAR_POS_X, $Col1X + 2 * (42 + 8) )
	set_control_par($ks3Button_id, $CONTROL_PAR_POS_Y, $PosY)
	set_control_par_str($ks3Button_id,$CONTROL_PAR_PICTURE,"Button_Ii")
	set_key_name(14,"[ARTICULATION] [i]")
	
	declare ui_button $ks4Button
	set_text ($ks4Button,@EMPTY)
	declare $ks4Button_id := get_ui_id($ks4Button)	
	set_control_par($ks4Button_id,$CONTROL_PAR_WIDTH,42)
	set_control_par($ks4Button_id,$CONTROL_PAR_HEIGHT,42)
	set_control_par($ks4Button_id, $CONTROL_PAR_POS_X, $Col1X + 3 * (42 + 8) )
	set_control_par($ks4Button_id, $CONTROL_PAR_POS_Y, $PosY)
	set_control_par_str($ks4Button_id,$CONTROL_PAR_PICTURE,"Button_Mm")
	set_key_name(15,"[ARTICULATION] [m]")
	
	declare ui_button $ks5Button
	set_text ($ks5Button,@EMPTY)
	declare $ks5Button_id := get_ui_id($ks5Button)	
	set_control_par($ks5Button_id,$CONTROL_PAR_WIDTH,42)
	set_control_par($ks5Button_id,$CONTROL_PAR_HEIGHT,42)
	set_control_par($ks5Button_id, $CONTROL_PAR_POS_X, $Col1X + 4 * (42 + 8) )
	set_control_par($ks5Button_id, $CONTROL_PAR_POS_Y, $PosY)
	set_control_par_str($ks5Button_id,$CONTROL_PAR_PICTURE,"Button_Oo")
	set_key_name(16,"[ARTICULATION] [o]")
	
	declare ui_button $ks6Button
	set_text ($ks6Button,@EMPTY)
	declare $ks6Button_id := get_ui_id($ks6Button)	
	set_control_par($ks6Button_id,$CONTROL_PAR_WIDTH,42)
	set_control_par($ks6Button_id,$CONTROL_PAR_HEIGHT,42)	
	set_control_par($ks6Button_id, $CONTROL_PAR_POS_X, $Col1X + 5 * (42 + 8) )
	set_control_par($ks6Button_id, $CONTROL_PAR_POS_Y, $PosY)
	set_control_par_str($ks6Button_id,$CONTROL_PAR_PICTURE,"Button_Uu")
	set_key_name(17,"[ARTICULATION] [u]")
	
	{ TITLES & SUBTITLES ------------------------------------------------------- }
	
	declare ui_label $titleLabel (1,1)
	set_text ($titleLabel,@titleEdit)
	hide_part($titleLabel,$HIDE_PART_BG)
	declare $titleLabel_id := get_ui_id($titleLabel)
	set_control_par($titleLabel_id,$CONTROL_PAR_WIDTH,110)
	set_control_par($titleLabel_id,$CONTROL_PAR_POS_X,4)
	set_control_par($titleLabel_id,$CONTROL_PAR_POS_Y,$PosY)
	set_control_par($titleLabel_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($titleLabel_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_MIDDLE)
	
	declare ui_label $subtitleLabel (1,1)
	set_text($subtitleLabel,@subtitleEdit)
	hide_part($subtitleLabel,$HIDE_PART_BG)
	declare $subtitleLabel_id := get_ui_id($subtitleLabel)
	set_control_par($subtitleLabel_id,$CONTROL_PAR_WIDTH,110)
	set_control_par($subtitleLabel_id,$CONTROL_PAR_POS_X,4)
	set_control_par($subtitleLabel_id,$CONTROL_PAR_POS_Y,$PosY + 15)
	set_control_par($subtitleLabel_id,$CONTROL_PAR_FONT_TYPE,$fontColor)
	set_control_par($subtitleLabel_id,$CONTROL_PAR_TEXT_ALIGNMENT,$ALIGN_MIDDLE)
	
	{ RULERS & MARKERS --------------------------------------------------------- }
	
	declare ui_panel $SATBPanel
	declare $SATBPanel_id := get_ui_id($SATBPanel)	
	move_control($SATBPanel,1,1)
	set_control_par($SATBPanel_id,$CONTROL_PAR_Z_LAYER,1)
	
	declare ui_label $SATBRulerLbl(1,1)
	set_text ($SATBRulerLbl,"")
	declare $SATBRulerLbl_id := get_ui_id($SATBRulerLbl)
	set_control_par_str($SATBRulerLbl_id,$CONTROL_PAR_PICTURE,"SATB_Ruler")
	set_control_par($SATBRulerLbl_id,$CONTROL_PAR_Z_LAYER,-2)
	set_control_par($SATBRulerLbl_id,$CONTROL_PAR_WIDTH,300)
	set_control_par($SATBRulerLbl_id,$CONTROL_PAR_HEIGHT,50)
	set_control_par($SATBRulerLbl_id,$CONTROL_PAR_POS_X,$Col2X)
	set_control_par($SATBRulerLbl_id,$CONTROL_PAR_POS_Y,10)	
	set_control_par($SATBRulerLbl_id,$CONTROL_PAR_PARENT_PANEL,$SATBPanel_id)
	
	declare ui_label $MarkerS1Lbl(1,1)
	set_text ($MarkerS1Lbl,"")
	declare $MarkerS1Lbl_id := get_ui_id($MarkerS1Lbl)
	set_control_par_str($MarkerS1Lbl_id,$CONTROL_PAR_PICTURE,"SATB_S1")
	set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_WIDTH,40)
	set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_HEIGHT,43)
	set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_POS_X,$DEFAULT_X_LEFT)
	set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_POS_Y,15)	
	set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_PARENT_PANEL,$SATBPanel_id)
	set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	declare ui_label $MarkerS2Lbl(1,1)
	set_text ($MarkerS2Lbl,"")
	declare $MarkerS2Lbl_id := get_ui_id($MarkerS2Lbl)
	set_control_par_str($MarkerS2Lbl_id,$CONTROL_PAR_PICTURE,"SATB_S2")
	set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_WIDTH,40)
	set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_HEIGHT,43)
	set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_POS_X,$DEFAULT_X_RIGHT)
	set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_POS_Y,15)	
	set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_PARENT_PANEL,$SATBPanel_id)
	set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	declare ui_label $MarkerT1Lbl(1,1)
	set_text ($MarkerT1Lbl,"")
	declare $MarkerT1Lbl_id := get_ui_id($MarkerT1Lbl)
	set_control_par_str($MarkerT1Lbl_id,$CONTROL_PAR_PICTURE,"SATB_T1")
	set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_WIDTH,40)
	set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_HEIGHT,43)
	set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_POS_X,$DEFAULT_X_LEFT)
	set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_POS_Y,15)	
	set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_PARENT_PANEL,$SATBPanel_id)
	set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	declare ui_label $MarkerT2Lbl(1,1)
	set_text ($MarkerT2Lbl,"")
	declare $MarkerT2Lbl_id := get_ui_id($MarkerT2Lbl)
	set_control_par_str($MarkerT2Lbl_id,$CONTROL_PAR_PICTURE,"SATB_T2")
	set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_WIDTH,40)
	set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_HEIGHT,43)
	set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_POS_X,$DEFAULT_X_RIGHT)
	set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_POS_Y,15)	
	set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_PARENT_PANEL,$SATBPanel_id)
	set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	declare ui_label $MarkerA1Lbl(1,1)
	set_text ($MarkerA1Lbl,"")
	declare $MarkerA1Lbl_id := get_ui_id($MarkerA1Lbl)
	set_control_par_str($MarkerA1Lbl_id,$CONTROL_PAR_PICTURE,"SATB_A1")
	set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_WIDTH,40)
	set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_HEIGHT,43)
	set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_POS_X,$DEFAULT_X_LEFT)
	set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_POS_Y,15)	
	set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_PARENT_PANEL,$SATBPanel_id)
	set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	declare ui_label $MarkerA2Lbl(1,1)
	set_text ($MarkerA2Lbl,"")
	declare $MarkerA2Lbl_id := get_ui_id($MarkerA2Lbl)
	set_control_par_str($MarkerA2Lbl_id,$CONTROL_PAR_PICTURE,"SATB_A2")
	set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_WIDTH,40)
	set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_HEIGHT,43)
	set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_POS_X,$DEFAULT_X_RIGHT)
	set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_POS_Y,15)	
	set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_PARENT_PANEL,$SATBPanel_id)
	set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	declare ui_label $MarkerB1Lbl(1,1)
	set_text ($MarkerB1Lbl,"")
	declare $MarkerB1Lbl_id := get_ui_id($MarkerB1Lbl)
	set_control_par_str($MarkerB1Lbl_id,$CONTROL_PAR_PICTURE,"SATB_B1")
	set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_WIDTH,40)
	set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_HEIGHT,43)
	set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_POS_X,$DEFAULT_X_LEFT)
	set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_POS_Y,15)	
	set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_PARENT_PANEL,$SATBPanel_id)
	set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	declare ui_label $MarkerB2Lbl(1,1)
	set_text ($MarkerB2Lbl,"")
	declare $MarkerB2Lbl_id := get_ui_id($MarkerB2Lbl)
	set_control_par_str($MarkerB2Lbl_id,$CONTROL_PAR_PICTURE,"SATB_B2")
	set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_Z_LAYER,-1)
	set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_WIDTH,40)
	set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_HEIGHT,43)
	set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_POS_X,$DEFAULT_X_RIGHT)
	set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_POS_Y,15)	
	set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_PARENT_PANEL,$SATBPanel_id)
	set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	{ PERSISTENCE -------------------------------------------------------------- }
		
	make_persistent($flegatoDuration)
	
	make_persistent(%modulesStatus)
	make_persistent(%modulesValues)
	make_persistent(%modulesAllowed)
	
	make_persistent($item1Toggle)
	make_persistent($item1Slider)
	
	make_persistent($item2Toggle)
	make_persistent($item2Slider)
	
	make_persistent($item3Toggle)
	make_persistent($item3Slider)
	
	make_persistent($item4Toggle)
	make_persistent($item4Slider)
	
	make_persistent($item5Toggle)
	make_persistent($item5Slider)	
	
	make_persistent(@titleEdit)	
	make_persistent(@subtitleEdit)
	
	make_persistent($currentKeyswitch)
	
	make_persistent($dynamicsDrivenByVel)
	make_persistent($expressionDrivenByVel)
	
	make_persistent($disableSopranoSwitch)
	make_persistent($disableAltoSwitch)
	make_persistent($disableTenorSwitch)
	make_persistent($disableBassSwitch)
	
	make_persistent($attackMode)
	
	{ -------------------------------------------------------------------------- }
	
	message(@EMPTY)	

end on

{ ---------------------------------------------------------------------------- }
function RepaintMarkers

	{ Lerp function to compute position }
	{ Lerp(a,b,t) = a + t * (b-a) }
	{ Compute t - Between 0 and 1 }	
	~realVar0 := int_to_real( %modulesValues[$MODULE_S_GRP1_PAN] ) / 1000000.0
	{ Compute X position }
	~realVar1 := ~X_MIN + (~realVar0 * (~X_MAX - ~X_MIN))
	{ Marker on position }
	set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_POS_X,real_to_int(~realVar1))

	{ Lerp function to compute position }
	{ Lerp(a,b,t) = a + t * (b-a) }
	{ Compute t - Between 0 and 1 }	
	~realVar0 := int_to_real( %modulesValues[$MODULE_S_GRP2_PAN] ) / 1000000.0
	{ Compute X position }
	~realVar1 := ~X_MIN + (~realVar0 * (~X_MAX - ~X_MIN))
	{ Marker on position }
	set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_POS_X,real_to_int(~realVar1))

	{ Lerp function to compute position }
	{ Lerp(a,b,t) = a + t * (b-a) }
	{ Compute t - Between 0 and 1 }	
	~realVar0 := int_to_real( %modulesValues[$MODULE_A_GRP1_PAN] ) / 1000000.0
	{ Compute X position }
	~realVar1 := ~X_MIN + (~realVar0 * (~X_MAX - ~X_MIN))
	{ Marker on position }
	set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_POS_X,real_to_int(~realVar1))

	{ Lerp function to compute position }
	{ Lerp(a,b,t) = a + t * (b-a) }
	{ Compute t - Between 0 and 1 }	
	~realVar0 := int_to_real( %modulesValues[$MODULE_A_GRP2_PAN] ) / 1000000.0
	{ Compute X position }
	~realVar1 := ~X_MIN + (~realVar0 * (~X_MAX - ~X_MIN))
	{ Marker on position }
	set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_POS_X,real_to_int(~realVar1))

	{ Lerp function to compute position }
	{ Lerp(a,b,t) = a + t * (b-a) }
	{ Compute t - Between 0 and 1 }	
	~realVar0 := int_to_real( %modulesValues[$MODULE_T_GRP1_PAN] ) / 1000000.0
	{ Compute X position }
	~realVar1 := ~X_MIN + (~realVar0 * (~X_MAX - ~X_MIN))
	{ Marker on position }
	set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_POS_X,real_to_int(~realVar1))

	{ Lerp function to compute position }
	{ Lerp(a,b,t) = a + t * (b-a) }
	{ Compute t - Between 0 and 1 }	
	~realVar0 := int_to_real( %modulesValues[$MODULE_T_GRP2_PAN] ) / 1000000.0
	{ Compute X position }
	~realVar1 := ~X_MIN + (~realVar0 * (~X_MAX - ~X_MIN))
	{ Marker on position }
	set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_POS_X,real_to_int(~realVar1))

	{ Lerp function to compute position }
	{ Lerp(a,b,t) = a + t * (b-a) }
	{ Compute t - Between 0 and 1 }	
	~realVar0 := int_to_real( %modulesValues[$MODULE_B_GRP1_PAN] ) / 1000000.0
	{ Compute X position }
	~realVar1 := ~X_MIN + (~realVar0 * (~X_MAX - ~X_MIN))
	{ Marker on position }
	set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_POS_X,real_to_int(~realVar1))


	{ Lerp function to compute position }
	{ Lerp(a,b,t) = a + t * (b-a) }
	{ Compute t - Between 0 and 1 }	
	~realVar0 := int_to_real( %modulesValues[$MODULE_B_GRP2_PAN] ) / 1000000.0
	{ Compute X position }
	~realVar1 := ~X_MIN + (~realVar0 * (~X_MAX - ~X_MIN))
	{ Marker on position }
	set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_POS_X,real_to_int(~realVar1))

end function

{ ---------------------------------------------------------------------------- }
function ShowHideMarkers
	
	{ SOPRANO ------------------------------------------------------------------ }
	
	if( $disableSopranoSwitch = $FALSE )	
		if( %modulesStatus[$MODULE_S_GRP1_VOLUME] = $TRUE )
			set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
		else
			set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		end if
		if( %modulesStatus[$MODULE_S_GRP2_VOLUME] = $TRUE )
			set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
		else
			set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		end if			
	else 	
		set_control_par($MarkerS1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		set_control_par($MarkerS2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)		
	end if
	
	{ ALTO --------------------------------------------------------------------- }
	
	if( $disableAltoSwitch = $FALSE )	
		if( %modulesStatus[$MODULE_A_GRP1_VOLUME] = $TRUE )
			set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
		else
			set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		end if
		if( %modulesStatus[$MODULE_A_GRP2_VOLUME] = $TRUE )
			set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
		else
			set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		end if			
	else 	
		set_control_par($MarkerA1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		set_control_par($MarkerA2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)		
	end if
	
	{ TENOR --------------------------------------------------------------------- }
	
	if( $disableTenorSwitch = $FALSE )	
		if( %modulesStatus[$MODULE_T_GRP1_VOLUME] = $TRUE )
			set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
		else
			set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		end if
		if( %modulesStatus[$MODULE_T_GRP2_VOLUME] = $TRUE )
			set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
		else
			set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		end if			
	else 	
		set_control_par($MarkerT1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		set_control_par($MarkerT2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)		
	end if
	
	{ BASS --------------------------------------------------------------------- }
	
	if( $disableBassSwitch = $FALSE )	
		if( %modulesStatus[$MODULE_B_GRP1_VOLUME] = $TRUE )
			set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
		else
			set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		end if
		if( %modulesStatus[$MODULE_B_GRP2_VOLUME] = $TRUE )
			set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
		else
			set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		end if			
	else 	
		set_control_par($MarkerB1Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)	
		set_control_par($MarkerB2Lbl_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)		
	end if
	
	call RepaintMarkers
		
end function

{ ---------------------------------------------------------------------------- }
function PrintInfos

	if( $Silent = $FALSE )

		inc(%Timer[$TIMER_DEFAULT])
		
		if( %Timer[$TIMER_DEFAULT]>3 )
			%Timer[$TIMER_DEFAULT] := 3
		end if
		
		if( %Timer[$TIMER_DEFAULT]<1 )
			%Timer[$TIMER_DEFAULT] := 1
		end if
		
		set_text($editedValLbl,@strVar0)	
		message(@strVar0)		
		wait($TEMPO_DEFAULT)
		
		dec(%Timer[$TIMER_DEFAULT])
		if( %Timer[$TIMER_DEFAULT]=$ZERO )
			set_text($editedValLbl,@EMPTY)
			message(@EMPTY)	
		end if
		
	end if

end function

{ ---------------------------------------------------------------------------- }
function VerifyModuleIndex

	{ if( %modulesAllowed[$verifiedModuleIndex] = $FALSE ) }
		 
	while( $verifiedModuleIndex < $MODULES_COUNT and %modulesAllowed[$verifiedModuleIndex] = $FALSE )
		inc($verifiedModuleIndex)
	end while
	
	{ end if	 }
		
end function

{ ---------------------------------------------------------------------------- }
function VerifyModuleMaxIndex
	$intVar0 := $ZERO	
	$index0 := $MODULES_COUNT - 1
	while( $index0 > $ZERO )	
		if( not ($intVar0 = $MODULES_VISIBLE) )
			if( %modulesAllowed[$index0] = $TRUE )
				$verifiedModuleMaxIndex := $index0			
				inc($intVar0)
			end if
		end if		
		dec($index0)
	end while	
end function

{ ---------------------------------------------------------------------------- }
function Repaint

	$verifiedModuleIndex := $moduleIndex	
	call VerifyModuleIndex
	$verifiedModuleIndex1 := $verifiedModuleIndex
	
	set_text($item1Lbl,!modulesLabels[$verifiedModuleIndex])	
	$item1Toggle := %modulesStatus[$verifiedModuleIndex]
	$item1Slider := %modulesValues[$verifiedModuleIndex]
	set_control_par($item1Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])	
	
	inc($verifiedModuleIndex)	
	call VerifyModuleIndex
	$verifiedModuleIndex2 := $verifiedModuleIndex
	
	set_text($item2Lbl,!modulesLabels[$verifiedModuleIndex])
	$item2Toggle := %modulesStatus[$verifiedModuleIndex]
	$item2Slider := %modulesValues[$verifiedModuleIndex]
	set_control_par($item2Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])	
	
	inc($verifiedModuleIndex)	
	call VerifyModuleIndex
	$verifiedModuleIndex3 := $verifiedModuleIndex
	
	set_text($item3Lbl,!modulesLabels[$verifiedModuleIndex])
	$item3Toggle := %modulesStatus[$verifiedModuleIndex]
	$item3Slider := %modulesValues[$verifiedModuleIndex]
	set_control_par($item3Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])	
	
	inc($verifiedModuleIndex)	
	call VerifyModuleIndex
	$verifiedModuleIndex4 := $verifiedModuleIndex
	
	set_text($item4Lbl,!modulesLabels[$verifiedModuleIndex])
	$item4Toggle := %modulesStatus[$verifiedModuleIndex]
	$item4Slider := %modulesValues[$verifiedModuleIndex]
	set_control_par($item4Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])
	
	inc($verifiedModuleIndex)	
	call VerifyModuleIndex
	$verifiedModuleIndex5 := $verifiedModuleIndex
	
	set_text($item5Lbl,!modulesLabels[$verifiedModuleIndex])
	$item5Toggle := %modulesStatus[$verifiedModuleIndex]
	$item5Slider := %modulesValues[$verifiedModuleIndex]
	set_control_par($item5Slider_id,$CONTROL_PAR_DEFAULT_VALUE,%modulesDefaultValues[$verifiedModuleIndex])
	
	call ShowHideMarkers
	
	{ Titles ------------------------------------------------------------------- }
	
	set_text($titleLabel,@titleEdit)
	set_text($subtitleLabel,@subtitleEdit)
	
end function

{ ---------------------------------------------------------------------------- }
function PerformPostInit
	
	%modulesDefaultStatus[$MODULE_DYNAMICS] := $TRUE
	%modulesDefaultStatus[$MODULE_EXPRESSION] := $TRUE
	
	%modulesDefaultStatus[$MODULE_REVERB_SLEVEL] := $TRUE	
	%modulesDefaultStatus[$MODULE_REVERB_MODE] := $TRUE	
	
	%modulesDefaultStatus[$MODULE_S_GRP1_VOLUME] := $TRUE	
	%modulesDefaultStatus[$MODULE_S_GRP1_PAN] := $TRUE	
	%modulesDefaultStatus[$MODULE_S_GRP2_VOLUME] := $TRUE	
	%modulesDefaultStatus[$MODULE_S_GRP2_PAN] := $TRUE	
	%modulesDefaultStatus[$MODULE_A_GRP1_VOLUME] := $TRUE	
	%modulesDefaultStatus[$MODULE_A_GRP1_PAN] := $TRUE	
	%modulesDefaultStatus[$MODULE_A_GRP2_VOLUME] := $TRUE	
	%modulesDefaultStatus[$MODULE_A_GRP2_PAN] := $TRUE
	%modulesDefaultStatus[$MODULE_T_GRP1_VOLUME] := $TRUE	
	%modulesDefaultStatus[$MODULE_T_GRP1_PAN] := $TRUE	
	%modulesDefaultStatus[$MODULE_T_GRP2_VOLUME] := $TRUE	
	%modulesDefaultStatus[$MODULE_T_GRP2_PAN] := $TRUE
	%modulesDefaultStatus[$MODULE_B_GRP1_VOLUME] := $TRUE	
	%modulesDefaultStatus[$MODULE_B_GRP1_PAN] := $TRUE	
	%modulesDefaultStatus[$MODULE_B_GRP2_VOLUME] := $TRUE	
	%modulesDefaultStatus[$MODULE_B_GRP2_PAN] := $TRUE
		
	$index0 := $ZERO
	while( $index0 < $MODULES_COUNT )
		%modulesAllowed[$index0] := $TRUE
		inc($index0)
	end while
	
	{ SOPRANO ------------------------------------------------------------------ }
	
	if( $disableSopranoSwitch = $FALSE )
	
		%modulesAllowed[$MODULE_S_GRP1_VOLUME] := $TRUE
		%modulesAllowed[$MODULE_S_GRP1_PAN] := $TRUE	
		%modulesAllowed[$MODULE_S_GRP2_VOLUME] := $TRUE
		%modulesAllowed[$MODULE_S_GRP2_PAN] := $TRUE
			
	else 
	
		%modulesAllowed[$MODULE_S_GRP1_VOLUME] := $FALSE
		%modulesAllowed[$MODULE_S_GRP1_PAN] := $FALSE	
		%modulesAllowed[$MODULE_S_GRP2_VOLUME] := $FALSE
		%modulesAllowed[$MODULE_S_GRP2_PAN] := $FALSE	
		
	end if
	
	{ ALTO --------------------------------------------------------------------- }
	
	if( $disableAltoSwitch = $FALSE )
	
		%modulesAllowed[$MODULE_A_GRP1_VOLUME] := $TRUE
		%modulesAllowed[$MODULE_A_GRP1_PAN] := $TRUE	
		%modulesAllowed[$MODULE_A_GRP2_VOLUME] := $TRUE
		%modulesAllowed[$MODULE_A_GRP2_PAN] := $TRUE	
			
	else 
	
		%modulesAllowed[$MODULE_A_GRP1_VOLUME] := $FALSE
		%modulesAllowed[$MODULE_A_GRP1_PAN] := $FALSE	
		%modulesAllowed[$MODULE_A_GRP2_VOLUME] := $FALSE
		%modulesAllowed[$MODULE_A_GRP2_PAN] := $FALSE	
		
	end if
	
	{ TENOR --------------------------------------------------------------------- }
	
	if( $disableTenorSwitch = $FALSE )
	
		%modulesAllowed[$MODULE_T_GRP1_VOLUME] := $TRUE
		%modulesAllowed[$MODULE_T_GRP1_PAN] := $TRUE	
		%modulesAllowed[$MODULE_T_GRP2_VOLUME] := $TRUE
		%modulesAllowed[$MODULE_T_GRP2_PAN] := $TRUE	
			
	else 
	
		%modulesAllowed[$MODULE_T_GRP1_VOLUME] := $FALSE
		%modulesAllowed[$MODULE_T_GRP1_PAN] := $FALSE	
		%modulesAllowed[$MODULE_T_GRP2_VOLUME] := $FALSE
		%modulesAllowed[$MODULE_T_GRP2_PAN] := $FALSE	
		
	end if
	
	{ BASS --------------------------------------------------------------------- }
	
	if( $disableBassSwitch = $FALSE )
	
		%modulesAllowed[$MODULE_B_GRP1_VOLUME] := $TRUE
		%modulesAllowed[$MODULE_B_GRP1_PAN] := $TRUE	
		%modulesAllowed[$MODULE_B_GRP2_VOLUME] := $TRUE
		%modulesAllowed[$MODULE_B_GRP2_PAN] := $TRUE	
			
	else 
	
		%modulesAllowed[$MODULE_B_GRP1_VOLUME] := $FALSE
		%modulesAllowed[$MODULE_B_GRP1_PAN] := $FALSE	
		%modulesAllowed[$MODULE_B_GRP2_VOLUME] := $FALSE
		%modulesAllowed[$MODULE_B_GRP2_PAN] := $FALSE	
		
	end if
	
	{ Curve -33 }
	{ Hold 0 }
	{ Decay  = Release = Attack = 600 ms because ATTACK and RELEASE are modulated by Velocity }
	{ Sustain 0 }
	
	$index0 := 0
	while($index0<$NUM_GROUPS)
		{ set_engine_par($ENGINE_PAR_ATTACK,162500,$index0,find_mod($index0,"VOL_ENV"),-1) }
		{ set_engine_par($ENGINE_PAR_ATTACK,384800,$index0,find_mod($index0,"VOL_ENV"),-1) }
		{ set_engine_par($ENGINE_PAR_ATTACK,639610,$index0,find_mod($index0,"VOL_ENV"),-1) }
		
		if( $attackMode = $TRUE )
			set_engine_par($ENGINE_PAR_ATTACK,639610,$index0,find_mod($index0,"VOL_ENV"),-1)
			%modulesDefaultValues[$MODULE_ATTACK] := 639610
			!modulesLabels[$MODULE_ATTACK] := "ATTACK | Default = 600 ms"				
		else
			set_engine_par($ENGINE_PAR_ATTACK,384800,$index0,find_mod($index0,"VOL_ENV"),-1)
			%modulesDefaultValues[$MODULE_ATTACK] := 384800
			!modulesLabels[$MODULE_ATTACK] := "ATTACK | Default = 60 ms"				
		end if
		
		
		set_engine_par($ENGINE_PAR_RELEASE,604980,$index0,find_mod($index0,"VOL_ENV"),-1)
		set_engine_par($ENGINE_PAR_DECAY,604980,$index0,find_mod($index0,"VOL_ENV"),-1)
		inc($index0)
	end while	
	
	{ Build keyswitches mapping }
	
	$index0 := 0				
	while( $index0 < $NUM_GROUPS )		
	
		if( get_engine_par($ENGINE_PAR_START_CRITERIA_MODE,$index0,0,-1) = $START_CRITERIA_ON_KEY )	
		
			%keyswitches_note[$index0] := get_engine_par($ENGINE_PAR_START_CRITERIA_KEY_MIN,$index0,0,-1)	

		end if
		
		inc($index0)
		
	end while	
	
	{ Put limiter to -6 dB output }
	{ set_engine_par($ENGINE_PAR_INSERT_EFFECT_OUTPUT_GAIN,315000,-1,$SLOT_LIMITER,$NI_MAIN_BUS) }
	{ Put limiter to -3 dB output }
	set_engine_par($ENGINE_PAR_INSERT_EFFECT_OUTPUT_GAIN,354000,-1,$SLOT_LIMITER,$NI_MAIN_BUS)
	
		
	call ShowHideMarkers
	call VerifyModuleMaxIndex
	call Repaint
	
	$ks1Button := $TRUE
	
end function

{ ---------------------------------------------------------------------------- }
on ui_control ($configButton)	
	move_control($SATBPanel,0,0)
	move_control($configPanel,1,1)
	set_control_par($configBg_id,$CONTROL_PAR_HIDE,$HIDE_PART_NOTHING)
end on

{ ---------------------------------------------------------------------------- }
on ui_control ($configDoneButton)	

	{ UI Cleaning -------------------------------------------------------------- }

	$configButton := 0
	$configDoneButton := 0
	move_control($configPanel,0,0)	
	move_control($SATBPanel,1,1)
	set_control_par($configBg_id,$CONTROL_PAR_HIDE,$HIDE_WHOLE_CONTROL)
	
	{ CONFIG STUFF ------------------------------------------------------------- }
	
	call PerformPostInit
	call Repaint
	
end on

{ ---------------------------------------------------------------------------- }
function SetDynamics

	{ 7875 = 1000000 / 127 in order to have min CC value = 1 }
	if( %modulesValues[$MODULE_DYNAMICS] < 7875 )
		%modulesValues[$MODULE_DYNAMICS] := 7875
	end if
	
	$intVar0 := %modulesValues[$MODULE_DYNAMICS] * 127 / 1000000

	if( %modulesStatus[$MODULE_DYNAMICS] = $FALSE )	
		set_engine_par($ENGINE_PAR_GN_GAIN,$intVar0*1600+200000,-1,$SLOT_GN_DYN,$NI_INSERT_BUS)
		set_engine_par($ENGINE_PAR_CUTOFF,$intVar0*1600+800000,-1,$SLOT_CO_DYN,$NI_INSERT_BUS)	
	else	
		inc(%Timer[$TIMER_DEFAULT])	
		set_engine_par($ENGINE_PAR_GN_GAIN,$intVar0*1600+200000,-1,$SLOT_GN_DYN,$NI_INSERT_BUS)
		set_engine_par($ENGINE_PAR_CUTOFF,$intVar0*1600+800000,-1,$SLOT_CO_DYN,$NI_INSERT_BUS)	
		
		@strVar0 := "CC1 " & $intVar0
		call PrintInfos	
		
	end if
	
end function

{ ---------------------------------------------------------------------------- }
function SetExpression

	{ 7875 = 1000000 / 127 in order to have min CC value = 1 }
	if( %modulesValues[$MODULE_EXPRESSION] < 7875 )
		%modulesValues[$MODULE_EXPRESSION] := 7875
	end if
	
	$intVar0 := %modulesValues[$MODULE_EXPRESSION] * 127 / 1000000	

	if( %modulesStatus[$MODULE_EXPRESSION] = $FALSE )
		set_engine_par($ENGINE_PAR_GN_GAIN,$intVar0*1000+270000,-1,$SLOT_GN_EXP,$NI_INSERT_BUS)	
	else	
		inc(%Timer[$TIMER_DEFAULT])		
		set_engine_par($ENGINE_PAR_GN_GAIN,$intVar0*1000+270000,-1,$SLOT_GN_EXP,$NI_INSERT_BUS)

		@strVar0 := "CC11 " & $intVar0
		call PrintInfos	
		
	end if
	
end function

{ ---------------------------------------------------------------------------- }
function SetForcedVelocity
	
	{ 7875 = 1000000 / 127 in order to have min CC value = 1 }
	if( %modulesValues[$MODULE_FORCED_VELOCITY] < 7875 )
		%modulesValues[$MODULE_FORCED_VELOCITY] := 7875
	end if
	
	$forcedVelocity := %modulesValues[$MODULE_FORCED_VELOCITY] * 127 / 1000000	
	
	@strVar0 := $forcedVelocity
	call PrintInfos	
		
end function

{ ---------------------------------------------------------------------------- }
function SetVelocityToSampleStart
	
	$index0 := 0
	while($index0<$NUM_GROUPS)
		set_engine_par($ENGINE_PAR_MOD_TARGET_INTENSITY,%modulesValues[$MODULE_VELO_SAMPlE_START],$index0,find_mod($index0,"VEL_PITCH"),-1)
		inc($index0)
	end while
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_MOD_TARGET_INTENSITY,0,find_mod(0,"VEL_PITCH"),-1) & " %"
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetVelocityToVolume
	
	$index0 := 0
	while($index0<$NUM_GROUPS)
		set_engine_par($ENGINE_PAR_MOD_TARGET_INTENSITY,%modulesValues[$MODULE_VELO_VOLUME],$index0,find_mod($index0,"VEL_VOLUME"),-1)
		inc($index0)
	end while	
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_MOD_TARGET_INTENSITY,0,find_mod(0,"VEL_VOLUME"),-1) & " %"
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetVelocityToAttack
	
	$index0 := 0
	while($index0<$NUM_GROUPS)
		set_engine_par($ENGINE_PAR_MOD_TARGET_INTENSITY,%modulesValues[$MODULE_VELO_ATTACK],$index0,find_mod($index0,"VEL_ATTACK"),-1)
		inc($index0)
	end while
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_MOD_TARGET_INTENSITY,0,find_mod(0,"VEL_ATTACK"),-1) & " %"
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetVelocityToRelease
	
	$index0 := 0
	while($index0<$NUM_GROUPS)
		set_engine_par($ENGINE_PAR_MOD_TARGET_INTENSITY,%modulesValues[$MODULE_VELO_RELEASE],$index0,find_mod($index0,"RVEL_ATTACK"),-1)
		inc($index0)
	end while	
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_MOD_TARGET_INTENSITY,0,find_mod(0,"RVEL_ATTACK"),-1) & " %"
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetFakeLegato
	
	{ FROM 1 ms to 500 ms - The fade time in microseconds }
	{ Lerp function to compute duration }
	{ Lerp(a,b,t) = a + t * (b-a) }
	
	{ Compute t - Between 0 and 1 }
	~realVar0 := int_to_real( %modulesValues[$MODULE_FKLEGATO] ) / 1000000.0
	
	{ Compute Lerp}
	
	{ In milliseconds }
	~realVar1 := 1.0 + (~realVar0 * (500.0 - 1.0))
	
	{ In microseconds }
	$flegatoDuration := real_to_int(~realVar1) * 1000
	
	{ Transform back in ms integer }
	$intVar0 := $flegatoDuration / 1000
	
	@strVar0 :=  $intVar0 & " ms"
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetHumanize
	
	$intVar0 := %modulesValues[$MODULE_HUMANIZE] / 10000
	
	@strVar0 :=  $intVar0 & " %"
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetStereoSpread
	
	set_engine_par($ENGINE_PAR_STEREO,%modulesValues[$MODULE_STEREO_S],-1,$SLOT_STEREO,$NI_INSERT_BUS)
	
	@strVar0 := get_engine_par_disp($ENGINE_PAR_STEREO,-1,$SLOT_STEREO,$NI_INSERT_BUS) & " %"
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetStereoPan
	
	set_engine_par($ENGINE_PAR_STEREO_PAN,%modulesValues[$MODULE_STEREO_P],-1,$SLOT_STEREO,$NI_INSERT_BUS)
	
	@strVar0 := get_engine_par_disp($ENGINE_PAR_STEREO_PAN,-1,$SLOT_STEREO,$NI_INSERT_BUS)
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetReverbSendLvl
	
	set_engine_par($ENGINE_PAR_SENDLEVEL_0,%modulesValues[$MODULE_REVERB_SLEVEL],-1,$SLOT_SEND,$NI_INSERT_BUS)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_SENDLEVEL_0,-1,7,$NI_INSERT_BUS) & " dB"
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetReverbMode
	
	if( %modulesValues[$MODULE_REVERB_MODE]>500000 )
		set_engine_par($ENGINE_PAR_RV2_TYPE,$NI_REVERB2_TYPE_ROOM,-1,$SLOT_REVERB,$NI_SEND_BUS)
		@strVar0 :=  "Room"
	else
		set_engine_par($ENGINE_PAR_RV2_TYPE,$NI_REVERB2_TYPE_HALL,-1,$SLOT_REVERB,$NI_SEND_BUS)
		@strVar0 :=  "Hall"
	end if
	
	call PrintInfos	
	
end function

{ ---------------------------------------------------------------------------- }
function SetFundamentalGain
	
	$index0 := 0
	while($index0<$NUM_GROUPS)
		set_engine_par($ENGINE_PAR_GAIN1,%modulesValues[$MODULE_FUNDAMENTAL_GAIN],$index0,$SLOT_FUND_EQ,$MINUS)
		inc($index0)
	end while	
	
	@strVar0 := get_engine_par_disp($ENGINE_PAR_GAIN1,$ZERO,$SLOT_FUND_EQ,$MINUS) & " dB"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetFundamentalWidth
	
	$index0 := 0
	while($index0<$NUM_GROUPS)
		set_engine_par($ENGINE_PAR_BW1,%modulesValues[$MODULE_FUNDAMENTAL_WIDTH],$index0,$SLOT_FUND_EQ,$MINUS)
		inc($index0)
	end while	
	
	@strVar0 := get_engine_par_disp($ENGINE_PAR_BW1,$ZERO,$SLOT_FUND_EQ,$MINUS) & " oc"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetSopranoGrp1Volume
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_VOLUME, %modulesValues[$MODULE_S_GRP1_VOLUME], -1, -1, $NI_BUS_OFFSET + $BUS_S_GRP1)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_VOLUME,-1, -1, $NI_BUS_OFFSET + $BUS_S_GRP1) & " dB"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetSopranoGrp1Pan
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_PAN, %modulesValues[$MODULE_S_GRP1_PAN], -1, -1, $NI_BUS_OFFSET + $BUS_S_GRP1)
	call RepaintMarkers
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_PAN,-1, -1, $NI_BUS_OFFSET + $BUS_S_GRP1)
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetSopranoGrp2Volume
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_VOLUME, %modulesValues[$MODULE_S_GRP2_VOLUME], -1, -1, $NI_BUS_OFFSET + $BUS_S_GRP2)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_VOLUME,-1, -1, $NI_BUS_OFFSET + $BUS_S_GRP2) & " dB"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetSopranoGrp2Pan
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_PAN, %modulesValues[$MODULE_S_GRP2_PAN], -1, -1, $NI_BUS_OFFSET + $BUS_S_GRP2)
	call RepaintMarkers
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_PAN,-1, -1, $NI_BUS_OFFSET + $BUS_S_GRP2)
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetAltoGrp1Volume
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_VOLUME, %modulesValues[$MODULE_A_GRP1_VOLUME], -1, -1, $NI_BUS_OFFSET + $BUS_A_GRP1)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_VOLUME,-1, -1, $NI_BUS_OFFSET + $BUS_A_GRP1) & " dB"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetAltoGrp1Pan
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_PAN, %modulesValues[$MODULE_A_GRP1_PAN], -1, -1, $NI_BUS_OFFSET + $BUS_A_GRP1)
	call RepaintMarkers
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_PAN,-1, -1, $NI_BUS_OFFSET + $BUS_A_GRP1)
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetAltoGrp2Volume
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_VOLUME, %modulesValues[$MODULE_A_GRP2_VOLUME], -1, -1, $NI_BUS_OFFSET + $BUS_A_GRP2)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_VOLUME,-1, -1, $NI_BUS_OFFSET + $BUS_A_GRP2) & " dB"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetAltoGrp2Pan
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_PAN, %modulesValues[$MODULE_A_GRP2_PAN], -1, -1, $NI_BUS_OFFSET + $BUS_A_GRP2)
	call RepaintMarkers
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_PAN,-1, -1, $NI_BUS_OFFSET + $BUS_A_GRP2)
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetTenorGrp1Volume
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_VOLUME, %modulesValues[$MODULE_T_GRP1_VOLUME], -1, -1, $NI_BUS_OFFSET + $BUS_T_GRP1)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_VOLUME,-1, -1, $NI_BUS_OFFSET + $BUS_T_GRP1) & " dB"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetTenorGrp1Pan
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_PAN, %modulesValues[$MODULE_T_GRP1_PAN], -1, -1, $NI_BUS_OFFSET + $BUS_T_GRP1)
	call RepaintMarkers
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_PAN,-1, -1, $NI_BUS_OFFSET + $BUS_T_GRP1)
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetTenorGrp2Volume
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_VOLUME, %modulesValues[$MODULE_T_GRP2_VOLUME], -1, -1, $NI_BUS_OFFSET + $BUS_T_GRP2)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_VOLUME,-1, -1, $NI_BUS_OFFSET + $BUS_T_GRP2) & " dB"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetTenorGrp2Pan
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_PAN, %modulesValues[$MODULE_T_GRP2_PAN], -1, -1, $NI_BUS_OFFSET + $BUS_T_GRP2)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_PAN,-1, -1, $NI_BUS_OFFSET + $BUS_T_GRP2)
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetBassGrp1Volume
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_VOLUME, %modulesValues[$MODULE_B_GRP1_VOLUME], -1, -1, $NI_BUS_OFFSET + $BUS_B_GRP1)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_VOLUME,-1, -1, $NI_BUS_OFFSET + $BUS_B_GRP1) & " dB"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetBassGrp1Pan
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_PAN, %modulesValues[$MODULE_B_GRP1_PAN], -1, -1, $NI_BUS_OFFSET + $BUS_B_GRP1)
	call RepaintMarkers
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_PAN,-1, -1, $NI_BUS_OFFSET + $BUS_B_GRP1)
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetBassGrp2Volume
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_VOLUME, %modulesValues[$MODULE_B_GRP2_VOLUME], -1, -1, $NI_BUS_OFFSET + $BUS_B_GRP2)
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_VOLUME,-1, -1, $NI_BUS_OFFSET + $BUS_B_GRP2) & " dB"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetBassGrp2Pan
	
	$index0 := 0
	set_engine_par($ENGINE_PAR_PAN, %modulesValues[$MODULE_B_GRP2_PAN], -1, -1, $NI_BUS_OFFSET + $BUS_B_GRP2)
	call RepaintMarkers
	
	@strVar0 :=  get_engine_par_disp($ENGINE_PAR_PAN,-1, -1, $NI_BUS_OFFSET + $BUS_B_GRP2)
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function SetAttack
	
	$index0 := 0
	while($index0<$NUM_GROUPS)
		set_engine_par($ENGINE_PAR_ATTACK,%modulesValues[$MODULE_ATTACK],$index0,find_mod($index0,"VOL_ENV"),-1)
		inc($index0)
	end while		
	
	@strVar0 := get_engine_par_disp($ENGINE_PAR_ATTACK,$ZERO,find_mod($ZERO,"VOL_ENV"),-1) & " ms"
	call PrintInfos
	
end function

{ ---------------------------------------------------------------------------- }
function PerformToggleChange

	%modulesStatus[$moduleEditedIndex] := abs(%modulesStatus[$moduleEditedIndex]-1)
	
	select( $moduleEditedIndex )
	
		{ DYNAMICS --------------------------------------------------------------- }
		case $MODULE_DYNAMICS	
			if( $dynamicsDrivenByVel = $TRUE )		
				%modulesValues[$MODULE_DYNAMICS] := %modulesDefaultValues[$MODULE_DYNAMICS]
			else
				set_engine_par($ENGINE_PAR_EFFECT_BYPASS,abs(%modulesStatus[$moduleEditedIndex]-1),-1,$SLOT_GN_DYN,$NI_INSERT_BUS)
				set_engine_par($ENGINE_PAR_EFFECT_BYPASS,abs(%modulesStatus[$moduleEditedIndex]-1),-1,$SLOT_CO_DYN,$NI_INSERT_BUS)
			end if

		{ EXPRESSION ------------------------------------------------------------- }
		case $MODULE_EXPRESSION
			if( $expressionDrivenByVel = $TRUE )		
				%modulesValues[$MODULE_EXPRESSION] := %modulesDefaultValues[$MODULE_EXPRESSION]
			else
				set_engine_par($ENGINE_PAR_EFFECT_BYPASS,abs(%modulesStatus[$moduleEditedIndex]-1),-1,$SLOT_GN_EXP,$NI_INSERT_BUS)
			end if
			
		{ STEREO ----------------------------------------------------------------- }	
		case $MODULE_STEREO_S
			set_engine_par($ENGINE_PAR_EFFECT_BYPASS,abs(%modulesStatus[$moduleEditedIndex]-1),-1,$SLOT_STEREO,$NI_INSERT_BUS)	
			%modulesStatus[$moduleEditedIndex+1] := %modulesStatus[$moduleEditedIndex]
			
		case $MODULE_STEREO_P
			set_engine_par($ENGINE_PAR_EFFECT_BYPASS,abs(%modulesStatus[$moduleEditedIndex]-1),-1,$SLOT_STEREO,$NI_INSERT_BUS)
			%modulesStatus[$moduleEditedIndex-1] := %modulesStatus[$moduleEditedIndex]
		
		{ REVERBERATION ---------------------------------------------------------- }
		case $MODULE_REVERB_SLEVEL
			set_engine_par($ENGINE_PAR_SEND_EFFECT_BYPASS,abs(%modulesStatus[$moduleEditedIndex]-1),-1,0,-1)
			%modulesStatus[$moduleEditedIndex+1] := %modulesStatus[$moduleEditedIndex]
		case $MODULE_REVERB_MODE
			set_engine_par($ENGINE_PAR_SEND_EFFECT_BYPASS,abs(%modulesStatus[$moduleEditedIndex]-1),-1,0,-1)
			%modulesStatus[$moduleEditedIndex-1] := %modulesStatus[$moduleEditedIndex]			
			
		{ SOPRANO ---------------------------------------------------------------- }
		case $MODULE_S_GRP1_VOLUME
			if( %modulesStatus[$MODULE_S_GRP1_VOLUME] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_S_GRP1_VOLUME]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_S_GRP1)
			%modulesStatus[$MODULE_S_GRP1_PAN] := %modulesStatus[$MODULE_S_GRP1_VOLUME]
			
		case $MODULE_S_GRP1_PAN
			if( %modulesStatus[$MODULE_S_GRP1_PAN] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_S_GRP1_PAN]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_S_GRP1)
			%modulesStatus[$MODULE_S_GRP1_VOLUME] := %modulesStatus[$MODULE_S_GRP1_PAN]
			
		case $MODULE_S_GRP2_VOLUME
			if( %modulesStatus[$MODULE_S_GRP2_VOLUME] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_S_GRP2_VOLUME]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_S_GRP2)
			%modulesStatus[$MODULE_S_GRP2_PAN] := %modulesStatus[$MODULE_S_GRP2_VOLUME]
			
		case $MODULE_S_GRP2_PAN
			if( %modulesStatus[$MODULE_S_GRP2_PAN] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_S_GRP2_PAN]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_S_GRP2)
			%modulesStatus[$MODULE_S_GRP2_VOLUME] := %modulesStatus[$MODULE_S_GRP2_PAN]
			
		{ ALTO ------------------------------------------------------------------- }
		case $MODULE_A_GRP1_VOLUME
			if( %modulesStatus[$MODULE_A_GRP1_VOLUME] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_A_GRP1_VOLUME]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_A_GRP1)
			%modulesStatus[$MODULE_A_GRP1_PAN] := %modulesStatus[$MODULE_A_GRP1_VOLUME]
			
		case $MODULE_A_GRP1_PAN
			if( %modulesStatus[$MODULE_A_GRP1_PAN] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_A_GRP1_PAN]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_A_GRP1)
			%modulesStatus[$MODULE_A_GRP1_VOLUME] := %modulesStatus[$MODULE_A_GRP1_PAN]
			
		case $MODULE_A_GRP2_VOLUME
			if( %modulesStatus[$MODULE_A_GRP2_VOLUME] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_A_GRP2_VOLUME]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_A_GRP2)
			%modulesStatus[$MODULE_A_GRP2_PAN] := %modulesStatus[$MODULE_A_GRP2_VOLUME]
			
		case $MODULE_A_GRP2_PAN
			if( %modulesStatus[$MODULE_A_GRP2_PAN] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_A_GRP2_PAN]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_A_GRP2)
			%modulesStatus[$MODULE_A_GRP2_VOLUME] := %modulesStatus[$MODULE_A_GRP2_PAN]
			
		{ TENOR ------------------------------------------------------------------- }
		case $MODULE_T_GRP1_VOLUME
			if( %modulesStatus[$MODULE_T_GRP1_VOLUME] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_T_GRP1_VOLUME]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_T_GRP1)
			%modulesStatus[$MODULE_T_GRP1_PAN] := %modulesStatus[$MODULE_T_GRP1_VOLUME]
			
		case $MODULE_T_GRP1_PAN
			if( %modulesStatus[$MODULE_T_GRP1_PAN] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_T_GRP1_PAN]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_T_GRP1)
			%modulesStatus[$MODULE_T_GRP1_VOLUME] := %modulesStatus[$MODULE_T_GRP1_PAN]
			
		case $MODULE_T_GRP2_VOLUME
			if( %modulesStatus[$MODULE_T_GRP2_VOLUME] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_T_GRP2_VOLUME]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_T_GRP2)
			%modulesStatus[$MODULE_T_GRP2_PAN] := %modulesStatus[$MODULE_T_GRP2_VOLUME]
			
		case $MODULE_T_GRP2_PAN
			if( %modulesStatus[$MODULE_T_GRP2_PAN] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_T_GRP2_PAN]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_T_GRP2)
			%modulesStatus[$MODULE_T_GRP2_VOLUME] := %modulesStatus[$MODULE_T_GRP2_PAN]
			
		{ BASS ------------------------------------------------------------------- }
		case $MODULE_B_GRP1_VOLUME
			if( %modulesStatus[$MODULE_B_GRP1_VOLUME] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_B_GRP1_VOLUME]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_B_GRP1)
			%modulesStatus[$MODULE_B_GRP1_PAN] := %modulesStatus[$MODULE_B_GRP1_VOLUME]
			
		case $MODULE_B_GRP1_PAN
			if( %modulesStatus[$MODULE_B_GRP1_PAN] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_B_GRP1_PAN]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_B_GRP1)
			%modulesStatus[$MODULE_B_GRP1_VOLUME] := %modulesStatus[$MODULE_B_GRP1_PAN]
			
		case $MODULE_B_GRP2_VOLUME
			if( %modulesStatus[$MODULE_B_GRP2_VOLUME] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_B_GRP2_VOLUME]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_B_GRP2)
			%modulesStatus[$MODULE_B_GRP2_PAN] := %modulesStatus[$MODULE_B_GRP2_VOLUME]
			
		case $MODULE_B_GRP2_PAN
			if( %modulesStatus[$MODULE_B_GRP2_PAN] = $TRUE )
				$intVar0 := %modulesValues[$MODULE_B_GRP2_PAN]
			else
				$intVar0 := $ZERO
			end if
			set_engine_par($ENGINE_PAR_VOLUME, $intVar0, -1, -1, $NI_BUS_OFFSET + $BUS_B_GRP2)
			%modulesStatus[$MODULE_B_GRP2_VOLUME] := %modulesStatus[$MODULE_B_GRP2_PAN]
			
	end select
	
	call Repaint

end function

{ ---------------------------------------------------------------------------- }
function PerformSliderChange

	%modulesValues[$moduleEditedIndex] := $moduleEditedValue

	select( $moduleEditedIndex )
	
		{ DYNAMICS --------------------------------------------------------------- }
		case $MODULE_DYNAMICS	
			call SetDynamics
			
		{ EXPRESSION ------------------------------------------------------------- }
		case $MODULE_EXPRESSION
			call SetExpression	

		{ VELOCITY --------------------------------------------------------------- }
		case $MODULE_FORCED_VELOCITY
			call SetForcedVelocity
			
		case $MODULE_VELO_SAMPlE_START
			call SetVelocityToSampleStart
			
		case $MODULE_VELO_VOLUME
			call SetVelocityToVolume
			
		case $MODULE_VELO_ATTACK
			call SetVelocityToAttack
			
		case $MODULE_VELO_RELEASE
			call SetVelocityToRelease
			
		{ FAKE LEGATO ------------------------------------------------------------ }
		case $MODULE_FKLEGATO		
			call SetFakeLegato
		
		{ HUMANIZE --------------------------------------------------------------- }		
		case $MODULE_HUMANIZE
			call SetHumanize
			
		{ STEREO ----------------------------------------------------------------- }	
		case $MODULE_STEREO_S
			call SetStereoSpread
			
		case $MODULE_STEREO_P
			call SetStereoPan
			
		{ REVERBERATION ---------------------------------------------------------- }	
		case $MODULE_REVERB_SLEVEL
			call SetReverbSendLvl
		
		case $MODULE_REVERB_MODE
			call SetReverbMode
			
		{ SOPRANO ---------------------------------------------------------------- }	
		case $MODULE_S_GRP1_VOLUME
			call SetSopranoGrp1Volume		
			
		case $MODULE_S_GRP1_PAN
			call SetSopranoGrp1Pan	

		case $MODULE_S_GRP2_VOLUME
			call SetSopranoGrp2Volume		
			
		case $MODULE_S_GRP2_PAN
			call SetSopranoGrp2Pan

		{ ALTO ---------------------------------------------------------------- }	
		case $MODULE_A_GRP1_VOLUME
			call SetAltoGrp1Volume		
			
		case $MODULE_A_GRP1_PAN
			call SetAltoGrp1Pan	

		case $MODULE_A_GRP2_VOLUME
			call SetAltoGrp2Volume		
			
		case $MODULE_A_GRP2_PAN
			call SetAltoGrp2Pan	
			
		{ TENOR ---------------------------------------------------------------- }	
		case $MODULE_T_GRP1_VOLUME
			call SetTenorGrp1Volume		
			
		case $MODULE_T_GRP1_PAN
			call SetTenorGrp1Pan	

		case $MODULE_T_GRP2_VOLUME
			call SetTenorGrp2Volume		
			
		case $MODULE_T_GRP2_PAN
			call SetTenorGrp2Pan	
			
		{ BASS ---------------------------------------------------------------- }	
		case $MODULE_B_GRP1_VOLUME
			call SetBassGrp1Volume		
			
		case $MODULE_B_GRP1_PAN
			call SetBassGrp1Pan	

		case $MODULE_B_GRP2_VOLUME
			call SetBassGrp2Volume		
			
		case $MODULE_B_GRP2_PAN
			call SetBassGrp2Pan	
			
		{ FUNDAMENTAL ------------------------------------------------------------ }	
		case $MODULE_FUNDAMENTAL_GAIN
			call SetFundamentalGain
		
		case $MODULE_FUNDAMENTAL_WIDTH
			call SetFundamentalWidth
			
		{ ATTACK ------------------------------------------------------------ }	
		case $MODULE_ATTACK
			call SetAttack
			
	end select
	
end function

{ ---------------------------------------------------------------------------- }
function PerformKeyswitch

	$ks1Button := 0
	$ks2Button := 0
	$ks3Button := 0
	$ks4Button := 0
	$ks5Button := 0
	$ks6Button := 0

	select( $currentKeyswitch )
	
		case 0
			$ks1Button := 1
			@strVar0 :=  "[a]"
			
		case 1
			$ks2Button := 1
			@strVar0 :=  "[e]"
			
		case 2
			$ks3Button := 1
			@strVar0 :=  "[i]"
			
		case 3
			$ks4Button := 1
			@strVar0 :=  "[m]"
			
		case 4
			$ks5Button := 1
			@strVar0 :=  "[o]"
			
		case 5
			$ks6Button := 1
			@strVar0 :=  "[u]"
		
	end select
	
	$isKeyswitchUi := $TRUE
	play_note(%keyswitches_note[$currentKeyswitch],1,0,1000)
	
	
	call PrintInfos		

end function

{ ---------------------------------------------------------------------------- }
on ui_control ($attackMode)

	if( $attackMode = $TRUE )
		set_text ($attackMode,"ATTACK [ LONG ]")
	else
		set_text ($attackMode,"ATTACK [ SHORT ]")
	end if
	
end on

{ ---------------------------------------------------------------------------- }
on ui_control ($ks1Button)

	$currentKeyswitch := 0
	call PerformKeyswitch	
	
end on

{ ---------------------------------------------------------------------------- }
on ui_control ($ks2Button)
	
	$currentKeyswitch := 1
	call PerformKeyswitch	
	
end on

{ ---------------------------------------------------------------------------- }
on ui_control ($ks3Button)

	$currentKeyswitch := 2
	call PerformKeyswitch
	
end on

{ ---------------------------------------------------------------------------- }
on ui_control ($ks4Button)

	$currentKeyswitch := 3
	call PerformKeyswitch	
	
end on

{ ---------------------------------------------------------------------------- }
on ui_control ($ks5Button)

	$currentKeyswitch := 4
	call PerformKeyswitch	
	
end on

{ ---------------------------------------------------------------------------- }
on ui_control ($ks6Button)

	$currentKeyswitch := 5
	call PerformKeyswitch	
	
end on
	
{------------------------------------------------------------------------------}
on ui_control ($item1Toggle)

	$moduleEditedIndex := $verifiedModuleIndex1
	call PerformToggleChange
	
end on

{------------------------------------------------------------------------------}
on ui_control ($item2Toggle)

	$moduleEditedIndex := $verifiedModuleIndex2
	call PerformToggleChange
	
end on

{------------------------------------------------------------------------------}
on ui_control ($item3Toggle)

	$moduleEditedIndex := $verifiedModuleIndex3
	call PerformToggleChange
	
end on

{------------------------------------------------------------------------------}
on ui_control ($item4Toggle)

	$moduleEditedIndex := $verifiedModuleIndex4
	call PerformToggleChange
	
end on

{------------------------------------------------------------------------------}
on ui_control ($item5Toggle)

	$moduleEditedIndex := $verifiedModuleIndex5
	call PerformToggleChange
	
end on

{------------------------------------------------------------------------------}
on ui_control ($item1Slider)

	$moduleEditedIndex := $verifiedModuleIndex1
	$moduleEditedValue := $item1Slider
	if( %modulesStatus[$moduleEditedIndex] = $FALSE )
		$item1Slider := %modulesValues[$moduleEditedIndex]
		@strVar0 := "Disabled"
		call PrintInfos
		exit
	else
		call PerformSliderChange
	end if	
	
end on

{------------------------------------------------------------------------------}
on ui_control ($item2Slider)

	$moduleEditedIndex := $verifiedModuleIndex2
	$moduleEditedValue := $item2Slider
	if( %modulesStatus[$moduleEditedIndex] = $FALSE )
		$item2Slider := %modulesValues[$moduleEditedIndex]
		@strVar0 := "Disabled"
		call PrintInfos
		exit
	else
		call PerformSliderChange
	end if
	
end on

{------------------------------------------------------------------------------}
on ui_control ($item3Slider)

	$moduleEditedIndex := $verifiedModuleIndex3
	$moduleEditedValue := $item3Slider
	if( %modulesStatus[$moduleEditedIndex] = $FALSE )
		$item3Slider := %modulesValues[$moduleEditedIndex]
		@strVar0 := "Disabled"
		call PrintInfos
		exit
	else
		call PerformSliderChange
	end if
	
end on

{------------------------------------------------------------------------------}
on ui_control ($item4Slider)

	$moduleEditedIndex := $verifiedModuleIndex4
	$moduleEditedValue := $item4Slider
	if( %modulesStatus[$moduleEditedIndex] = $FALSE )
		$item4Slider := %modulesValues[$moduleEditedIndex]
		@strVar0 := "Disabled"
		call PrintInfos
		exit
	else
		call PerformSliderChange
	end if
	
end on

{------------------------------------------------------------------------------}
on ui_control ($item5Slider)

	$moduleEditedIndex := $verifiedModuleIndex5
	$moduleEditedValue := $item5Slider
	if( %modulesStatus[$moduleEditedIndex] = $FALSE )
		$item5Slider := %modulesValues[$moduleEditedIndex]
		@strVar0 := "Disabled"
		call PrintInfos
		exit
	else
		call PerformSliderChange
	end if
	
end on

{ ---------------------------------------------------------------------------- }
on ui_control ($KnobSel)
	
	$intVar0 := abs($KnobSel - $knobSelLastValue)

	if( $KnobSel > $knobSelLastValue )
		$knobSelDirection := $DOWN		
		if( $intVar0 > 1 )
			$KnobSel := $knobSelLastValue + 1
		end if		
	else
		if( $KnobSel < $knobSelLastValue )
			$knobSelDirection := $UP			
			if( $intVar0 > 1 )
				$KnobSel := $knobSelLastValue - 1
			end if			
		else
			$knobSelDirection := $STATIC 
		end if
	end if
	
	$knobSelLastValue := $KnobSel
	
	$moduleIndex := $moduleIndex + $knobSelDirection
	
	if( $moduleIndex > $verifiedModuleMaxIndex )
		 $moduleIndex := $verifiedModuleMaxIndex
	end if
	
	if( $moduleIndex < $ZERO ) 
		$moduleIndex := $ZERO
	end if
	
	call Repaint
		
end on

{ ---------------------------------------------------------------------------- }
on ui_control ($defaultValuesButton)

	$defaultValuesButton := 0	

	$Silent := $TRUE	
	
	$index1 := 0
	while( $index1 < $MODULES_COUNT )
		%modulesValues[$index1] := %modulesDefaultValues[$index1]		
		%modulesStatus[$index1] := %modulesDefaultStatus[$index1]		
		$moduleEditedValue := %modulesValues[$index1]
		$moduleEditedIndex := $index1
		call PerformSliderChange
		inc ($index1)
	end while	
	
	$Silent := $FALSE
	
	{ call Repaint }
		
end on

{ ---------------------------------------------------------------------------- }
on controller

	if( $CC_NUM=1 )
		%modulesValues[$MODULE_DYNAMICS] := %CC[1] * 1000000 / 127
		if( %modulesStatus[$MODULE_DYNAMICS] = $TRUE )
			call Repaint
			call SetDynamics
		end if		
	end if	
	
	if( $CC_NUM=11 )
		%modulesValues[$MODULE_EXPRESSION] := %CC[11] * 1000000 / 127
		if( %modulesStatus[$MODULE_EXPRESSION] = $TRUE )
			call Repaint
			call SetExpression
		end if
	end if	
	
end on

{ ---------------------------------------------------------------------------- }
on note

	{ GROUPS ----------------------------------------------------------------- }

	disallow_group($ALL_GROUPS)
	
	$intVar0 := $ZERO
		
	if( $disableSopranoSwitch = $FALSE )		

		if( %modulesStatus[$MODULE_S_GRP1_VOLUME] = $TRUE )
			$index0 := $ZERO
			while( $index0 < $GROUP_PER_DIVISI )
				allow_group($index0 + $intVar0) 
				inc($index0)
			end while
		end if
		
		if( %modulesStatus[$MODULE_S_GRP2_VOLUME] = $TRUE )
			$index0 := $ZERO
			while( $index0 < $GROUP_PER_DIVISI )
				allow_group($index0 + $intVar0 + $GROUP_PER_DIVISI) 
				inc($index0)
			end while
		end if
		
		$intVar0 := $intVar0 + $GROUP_PER_SECTION
		
	end if
	
	if( $disableAltoSwitch = $FALSE )	

		if( %modulesStatus[$MODULE_A_GRP1_VOLUME] = $TRUE )
			$index0 := $ZERO
			while( $index0 < $GROUP_PER_DIVISI )
				allow_group($index0 + $intVar0) 
				inc($index0)
			end while
		end if
		
		if( %modulesStatus[$MODULE_A_GRP2_VOLUME] = $TRUE )
			$index0 := $ZERO
			while( $index0 < $GROUP_PER_DIVISI )
				allow_group($index0 + $intVar0 + $GROUP_PER_DIVISI) 
				inc($index0)
			end while
		end if
		
		$intVar0 := $intVar0 + $GROUP_PER_SECTION
		
	end if
	
	if( $disableTenorSwitch = $FALSE )



		if( %modulesStatus[$MODULE_T_GRP1_VOLUME] = $TRUE )
			$index0 := $ZERO
			while( $index0 < $GROUP_PER_DIVISI )
				allow_group($index0 + $intVar0) 
				inc($index0)
			end while
		end if
		
		if( %modulesStatus[$MODULE_T_GRP2_VOLUME] = $TRUE )
			$index0 := $ZERO
			while( $index0 < $GROUP_PER_DIVISI )
				allow_group($index0 + $intVar0 + $GROUP_PER_DIVISI) 
				inc($index0)
			end while
		end if
		
		$intVar0 := $intVar0 + $GROUP_PER_SECTION
		
	end if
	
	if( $disableBassSwitch = $FALSE )	

		if( %modulesStatus[$MODULE_B_GRP1_VOLUME] = $TRUE )
			$index0 := $ZERO
			while( $index0 < $GROUP_PER_DIVISI )
				allow_group($index0 + $intVar0) 
				inc($index0)
			end while
		end if
		
		if( %modulesStatus[$MODULE_B_GRP2_VOLUME] = $TRUE )
			$index0 := $ZERO
			while( $index0 < $GROUP_PER_DIVISI )
				allow_group($index0 + $intVar0 + $GROUP_PER_DIVISI) 
				inc($index0)
			end while
		end if
		
		$intVar0 := $intVar0 + $GROUP_PER_SECTION
		
	end if

	{ HUMANIZE ----------------------------------------------------------------- }

	if( %modulesStatus[$MODULE_HUMANIZE] = $TRUE )
	
		$intVar0 := %modulesValues[$MODULE_HUMANIZE] / 10000
		$newVolume := (random (-60,60) * $intVar0) + get_event_par($EVENT_ID,$EVENT_PAR_VOLUME)
		$newPan := (random(-$intVar0*15,$intVar0*15)) + get_event_par($EVENT_ID,$EVENT_PAR_PAN)
		$newTune := (random (-1000,1000) * $intVar0) + get_event_par($EVENT_ID,$EVENT_PAR_TUNE)
		$newVelocity := $EVENT_VELOCITY + (random (-127,127) * $intVar0 / 200)
		
	else
	
		$newVelocity := $EVENT_VELOCITY
		
	end if
	
	{ VELOCITY ----------------------------------------------------------------- }
	
	if( %modulesStatus[$MODULE_FORCED_VELOCITY] = $TRUE )	
		$newVelocity := $forcedVelocity		
	end if	
	
	if( $newVelocity > 127 )
		$newVelocity := 127
	else if( $newVelocity < 1 )
			$newVelocity := 1
		end if 
	end if
	
	$KnobVelocity := $newVelocity

	{ DYNAMICS ----------------------------------------------------------------- }		
			
	if( %modulesStatus[$MODULE_DYNAMICS] = $FALSE and $dynamicsDrivenByVel = $TRUE )
		%modulesValues[$MODULE_DYNAMICS] := $newVelocity * 1000000 / 127
		call Repaint
		call SetDynamics
	end if		
	
	{ EXPRESSION --------------------------------------------------------------- }	
			
	if( %modulesStatus[$MODULE_EXPRESSION] = $FALSE and $expressionDrivenByVel = $TRUE )
		%modulesValues[$MODULE_EXPRESSION] := $newVelocity * 1000000 / 127
		call Repaint
		call SetExpression
	end if
	
	{ EVENT -------------------------------------------------------------------- }
	
	ignore_event($EVENT_ID)
		
	if( %modulesStatus[$MODULE_FKLEGATO] = $TRUE )
		if( %KEY_DOWN[$PreviousNote]=1 and $PreviousNote#$EVENT_NOTE )		
			fade_out($previousEvent,$flegatoDuration,1)			
			$newNote := $EVENT_NOTE
			$previousEvent := play_note($newNote,$newVelocity,0,-1)	
			if( %modulesStatus[$MODULE_HUMANIZE] = $TRUE )
				change_tune($previousEvent,$newTune,1)	
				change_vol ($previousEvent,$newVolume,1)
				change_pan ($previousEvent,$newPan,1)
			else
				change_tune($previousEvent,get_event_par($EVENT_ID,$EVENT_PAR_TUNE),1)
				change_vol($previousEvent,get_event_par($EVENT_ID,$EVENT_PAR_VOLUME),1)
				change_pan($previousEvent,get_event_par($EVENT_ID,$EVENT_PAR_PAN),1)	
			end if
			fade_in($previousEvent,$flegatoDuration)
			$PreviousNote := $newNote			
		else
			$previousEvent := play_note($EVENT_NOTE,$newVelocity,0,-1)
			if( %modulesStatus[$MODULE_HUMANIZE] = $TRUE )			
				change_tune($previousEvent,$newTune,1)
				change_vol ($previousEvent,$newVolume,1)
				change_pan ($previousEvent,$newPan,1)
			else
				change_tune($previousEvent,get_event_par($EVENT_ID,$EVENT_PAR_TUNE),1)
				change_vol($previousEvent,get_event_par($EVENT_ID,$EVENT_PAR_VOLUME),1)
				change_pan($previousEvent,get_event_par($EVENT_ID,$EVENT_PAR_PAN),1)	
			end if
			$PreviousNote := $EVENT_NOTE
		end if		
	else
		$previousEvent := play_note($EVENT_NOTE,$newVelocity,0,-1)
		if( %modulesStatus[$MODULE_HUMANIZE] = $TRUE )
			change_tune($previousEvent,$newTune,1)
			change_vol ($previousEvent,$newVolume,1)
			change_pan ($previousEvent,$newPan,1)
		else
			change_tune($previousEvent,get_event_par($EVENT_ID,$EVENT_PAR_TUNE),1)
			change_vol($previousEvent,get_event_par($EVENT_ID,$EVENT_PAR_VOLUME),1)
			change_pan($previousEvent,get_event_par($EVENT_ID,$EVENT_PAR_PAN),1)	
		end if		
	end if		
	
end on

{ ---------------------------------------------------------------------------- }
on release
	
	inc(%Timer[$TIMER_VELOCITY])

	if( $isKeyswitchUi = $FALSE )	
	
		select( $EVENT_NOTE )
			case 12
				$ks1Button := 1
				$ks2Button := 0
				$ks3Button := 0
				$ks4Button := 0
				$ks5Button := 0
				$ks6Button := 0
			case 13
				$ks1Button := 0
				$ks2Button := 1
				$ks3Button := 0
				$ks4Button := 0
				$ks5Button := 0
				$ks6Button := 0
			case 14
				$ks1Button := 0
				$ks2Button := 0
				$ks3Button := 1
				$ks4Button := 0
				$ks5Button := 0
				$ks6Button := 0
			case 15
				$ks1Button := 0
				$ks2Button := 0
				$ks3Button := 0
				$ks4Button := 1
				$ks5Button := 0
				$ks6Button := 0
			case 16
				$ks1Button := 0
				$ks2Button := 0
				$ks3Button := 0
				$ks4Button := 0
				$ks5Button := 1
				$ks6Button := 0
			case 17
				$ks1Button := 0
				$ks2Button := 0
				$ks3Button := 0
				$ks4Button := 0
				$ks5Button := 0
				$ks6Button := 1
		end select
	end if
	
	$isKeyswitchUi := $FALSE
	
	wait($TEMPO_VELOCITY)
	dec(%Timer[$TIMER_VELOCITY])
	if( %Timer[$TIMER_VELOCITY]=0 )
		$KnobVelocity := 0
	end if
end on

{ ---------------------------------------------------------------------------- }
on persistence_changed

	if( $initFlag = $TRUE )
	
		call PerformPostInit
	
		@strVar0 := "Init [Done]"	
		
		$initFlag := $FALSE
		
	else
	
		call PerformKeyswitch	
			
		@strVar0 := "Snapshot [Loaded] "
	
	end if
	
	call PrintInfos
	
end on

{ ---------------------------------------------------------------------------- }
